programing

CSMutableArray에 CGRect 값을 저장하는 방법은 무엇입니까?

projobs 2023. 6. 3. 09:32
반응형

CSMutableArray에 CGRect 값을 저장하는 방법은 무엇입니까?

CGRect 개체를 NSMutableArray에 저장한 다음 나중에 검색하려면 어떻게 해야 합니까?

CG 구조를 랩으로 감아야 합니다.NSValue반.그래서:

NSMutableArray* array = [NSMutableArray mutableArray];
[array addObject:[NSValue valueWithCGRect:CGRectMake(0,0,10,10)]];
CGRect someRect = [[array objectAtIndex:0] CGRectValue];
CGRect rect = CGRectMake( 5, 5, 40, 30 );
NSString* rectAsString = NSStringFromCGRect( rect );
CGRect original = CGRectFromString( rectAsString );

저장합니다.CGRect,CGPoint,CMTime의 물체.NSMutableArray,

[arrayName addObject:[NSValue valueWithCGPoint:MyCGPoint]]

[arrayName addObject:[NSValue valueWithCGRect:MyCGRect]]

[arrayName addObject:[NSValue valueWithCMTime:MyCMTime]]

[arrayName addObject:[NSValue valueWithCMTimeRange:MyCMTimeRange]]

Store string in array.and then get back string and convert that in CGRect back as per the need.
CGRect rect = CGRectMake( 5, 5, 40, 30 );
NSString* rectAsString = NSStringFromCGRect( rect );
NSMutableArray* array = [NSMutableArray mutableArray];
[array addObject:rectAsString];

For converting string in CGRect back use:-
CGRect rect9 = CGRectFromString(rectAsString);

언급URL : https://stackoverflow.com/questions/2934178/how-to-store-cgrect-values-in-nsmutablearray

반응형