iPhone : Best way to detect the end of UIImageView image sequence animation

前端 未结 3 1750
情深已故
情深已故 2021-01-18 00:41

We know that UIImageView has a very nice support for image sequence animation. We can easily create an array of UIImage objects, set the animationImages

3条回答
  •  鱼传尺愫
    2021-01-18 01:26

    I made this (method of my UIImageView subclass).

    -(void)startAnimatingWithCallback:(UIImageViewAnimationCompletitionBlock) completitionCallback
    {
        [self startAnimating];
    
        dispatch_queue_t animatingQueue = dispatch_get_current_queue();
        dispatch_queue_t pollingQueue = dispatch_queue_create("pollingQueue", NULL);
        dispatch_async(pollingQueue, ^{
    
            while(self.isAnimating) { usleep(10000); }
            dispatch_async(animatingQueue, ^{ if (completitionCallback) completitionCallback(); });
    
        });
    }
    

    Simple usage:

    [self.oneView fadeOut];
    [self.otherView startAnimatingWithCallback:^
    {
        [self.oneView fadeIn];
    }];
    

提交回复
热议问题