Access Method After UIImageView Animation Finish

后端 未结 7 946
清酒与你
清酒与你 2020-12-01 11:47

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

7条回答
  •  难免孤独
    2020-12-01 11:49

    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... */
    
           });
    
       });
    
    }
    

提交回复
热议问题