2010-05-29 4 views

Antwort

278

Sie müssen die CG-Strukturen in NSValue Klassen einbinden. Also:

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

gut! NSValue ist so nützlich ... danke – Joey

+0

weitere Beispiele hier: 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); 

Was denken Sie über diese Art und Weise CGRect Daten zu speichern?

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

Wir speichern die CGRect, CGPoint, CMTime Objekte in einem NSMutableArray,

[arrayName addObject:[NSValue valueWithCGPoint:MyCGPoint]]

[arrayName addObject:[NSValue valueWithCGRect:MyCGRect]]

[arrayName addObject:[NSValue valueWithCMTime:MyCMTime]]

[arrayName addObject:[NSValue valueWithCMTimeRange:MyCMTimeRange]]