Reputation: 3327
I have an NSArray with over 4.000 CGPoints
[NSArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(213, 30)], ...
and want to draw the points or lines between them from inside my UIViewController. What is the best way for iOS devices? thnx
Upvotes: 0
Views: 363
Reputation: 43472
Sounds like you're trying to work with sprites or particle generation? Without knowing more details, I can only give a generic answer, but lemme give it a shot. Let's assume the points are all simple 1-pixel coloured thingies. No gradients or paths required, just "set the pixel at x,y to red/green/blue."
You should easily be able to manipulate 4,000 CALayer
objects simultaneously:
CALayer *rootLayer = [[self view] layer]; // assumes self is a view controller
NSMutableArray *mSprites = [NSMutableArray array]; // to store references to the layers
for (int i = 0; i < 4000; i++) {
CALayer *layer = [CALayer layer];
NSAssert1(layer != nil, @"failed to create CALayer #%i", i);
layer.backgroundColor = [UIColor colorWithRed:... green:... blue:... alpha:1.0].CGColor;
layer.frame = CGRectMake(rand(), rand(), 1.0, 1.0);
[mSprites addObject:layer];
[rootLayer addSublayer:layer];
}
self.my4000SpritesProperty = mSprites;
Then, when it's time to manipulate them, go into the array at self.my4000SpritesProperty
and change the layers' frames or other properties.
For 4,000 elements, you should see acceptable performance with Core Animation.
Upvotes: 2