2010-05-29 19 views

Respuesta

278

Debe envolver las estructuras CG en las clases NSValue. Por lo tanto:

NSMutableArray* array = [NSMutableArray mutableArray]; 
[array addObject:[NSValue valueWithCGRect:CGRectMake(0,0,10,10)]]; 
CGRect someRect = [[array objectAtIndex:0] CGRectValue]; 
+0

bueno! NSValue es muy útil ... gracias – Joey

+0

más ejemplos aquí: http://iosdevelopertips.com/cocoa/storing-cgpoint-cgsize-and-cgrect-in-collections-using-nsvalue.html – WINSergey

12
CGRect rect = CGRectMake(5, 5, 40, 30); 
NSString* rectAsString = NSStringFromCGRect(rect); 
CGRect original = CGRectFromString(rectAsString); 

¿Qué opinas acerca de esta forma de almacenar fechas CGRect?

1
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); 
2

almacenamos la CGRect, CGPoint, CMTime objetos en un NSMutableArray,

[arrayName addObject:[NSValue valueWithCGPoint:MyCGPoint]]

[arrayName addObject:[NSValue valueWithCGRect:MyCGRect]]

[arrayName addObject:[NSValue valueWithCMTime:MyCMTime]]

[arrayName addObject:[NSValue valueWithCMTimeRange:MyCMTimeRange]]

Cuestiones relacionadas