Jak przechowywać wartości CGRect w NSMutableArray?

Jak przechowywać obiekty CGRect w NSMutableArray, a następnie je odzyskać?

Author: johnluttig, 2010-05-29

4 answers

Musisz zawinąć struktury CG w klasy NSValue. Więc:

NSMutableArray* array = [NSMutableArray mutableArray];
[array addObject:[NSValue valueWithCGRect:CGRectMake(0,0,10,10)]];
CGRect someRect = [[array objectAtIndex:0] CGRectValue];
 279
Author: Jason Coco,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-29 07:22:53
CGRect rect = CGRectMake( 5, 5, 40, 30 );
NSString* rectAsString = NSStringFromCGRect( rect );
CGRect original = CGRectFromString( rectAsString );

Co sądzisz o tym sposobie przechowywania dat CGRect?

 12
Author: Jane,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-25 10:24:17

Przechowujemy CGRect,CGPoint,CMTime obiekty w NSMutableArray,

[arrayName addObject:[NSValue valueWithCGPoint:MyCGPoint]]

[arrayName addObject:[NSValue valueWithCGRect:MyCGRect]]

[arrayName addObject:[NSValue valueWithCMTime:MyCMTime]]

[arrayName addObject:[NSValue valueWithCMTimeRange:MyCMTimeRange]]

 2
Author: Vaibhav Sharma,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-11 07:54:04
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);
 1
Author: Tanvi Jain,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-12 14:05:29