How to pause and resume UIView Animation?

后端 未结 5 1342
长发绾君心
长发绾君心 2020-12-10 08:28

I have a UIView with several UILabels that is animating from top to bottom and vice versa. A sort of Autoque let\'s say :) I use 2 functions:

-(void)goUp 
-(         


        
5条回答
  •  粉色の甜心
    2020-12-10 09:14

    I've created a category on UIView to pause and stop animations:

    @interface UIView (AnimationsHandler)
    
    - (void)pauseAnimations;
    - (void)resumeAnimations;
    
    @end
    
    @implementation UIView (AnimationsHandler)
    - (void)pauseAnimations
    {
        CFTimeInterval paused_time = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil];
        self.layer.speed = 0.0;
        self.layer.timeOffset = paused_time;
    }
    
    - (void)resumeAnimations
    {
        CFTimeInterval paused_time = [self.layer timeOffset];
        self.layer.speed = 1.0f;
        self.layer.timeOffset = 0.0f;
        self.layer.beginTime = 0.0f;
        CFTimeInterval time_since_pause = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil] - paused_time;
        self.layer.beginTime = time_since_pause;
    }
    

提交回复
热议问题