I have an array of images loaded into a UIImageView that I am animating through one cycle. After the images have been displayed, I would like a @selector to be
With this method you avoid timers to fire while the imageView is still animating due to slow image loading.
You could use both performSelector: withObject: afterDelay: and GCD in this way:
[self performSelector:@selector(didFinishAnimatingImageView:)
withObject:imageView
afterDelay:imageView.animationDuration];
/!\ self.imageView.animationDuration has to bet configured before startAnimating, otherwise it will be 0
Than if -(void)didFinishAnimatingImageView:create a background queue, perform a check on the isAnimating property, than execute the rest on the main queue
- (void)didFinishAnimatingImageView:(UIImageView*)imageView
{
dispatch_queue_t backgroundQueue = dispatch_queue_create("com.yourcompany.yourapp.checkDidFinishAnimatingImageView", 0);
dispatch_async(backgroundQueue, ^{
while (self.imageView.isAnimating)
NSLog(@"Is animating... Waiting...");
dispatch_async(dispatch_get_main_queue(), ^{
/* All the rest... */
});
});
}