Reputation: 615
I got a problem with drawing on UIImageView
with delay. I got method [className drawPoint:(CGPoint)point]
(this method can draw point and it works fine )
Next I want to draw 3 points from array in circle with a 1 sec delay, and if I use [self performSelector:withObject:afterDelay:]
I will see all 3 points on UIImageView
after 3 seconds delay. But I want it to draw point1 then after 1 second point2 and then after 1 second point3.
I've also tried to play with dispatch_async
but didn't get desired result
Upvotes: 0
Views: 184
Reputation: 346
Try to use:
[self performSelectorInBackground:@selector(drawThreePoints) withObject:nil];
The drawThreePoints method:
-(void)drawThreePoints{
[NSThread sleepForTimeInterval:1];
[self performSelectorOnMainThread:@selector(drawPoint:) withObject:POINT1 waitUntilDone:NO];
[NSThread sleepForTimeInterval:1];
[self performSelectorOnMainThread:@selector(drawPoint:) withObject:POINT2 waitUntilDone:NO];
[NSThread sleepForTimeInterval:1];
[self performSelectorOnMainThread:@selector(drawPoint:) withObject:POINT3 waitUntilDone:NO];
}
The drawPoint: method:
-(void)drawPoint:(CGPoint)point{
[className drawPoint:point];
}
UPD: Or, if points are from array, you can do it in the loop, of course :)
Upvotes: 1
Reputation: 1427
If you want to stagger the drawing of a view, drawRect
is not the place to do it. A better solution would be to draw everything you want to draw in drawRect
(or separate out your staggered elements into different views each with their own drawRect
) and to toggle the hidden property with UIView
's class method animateWithDuration
.
Upvotes: 2