美文网首页
iOS10中用UIViewPropertyAnimator来书写

iOS10中用UIViewPropertyAnimator来书写

作者: zhouios | 来源:发表于2016-09-23 11:11 被阅读0次

    UIViewPropertyAnimator是修改动画属性的核心类,它提供了中断动画、修改动画中间过程的功能;

    - (void)viewDidLoad {
        [super viewDidLoad];
       
        UIView *redView = [[UIView alloc] init];
        redView.frame = CGRectMake(100, 100, 100, 100);
        redView.backgroundColor = [UIColor redColor];
        [self.view addSubview:redView];
        /*
         这是苹果提供的4中曲线
         UIViewAnimationCurveEaseInOut,         // slow at beginning and end
         UIViewAnimationCurveEaseIn,            // slow at beginning
         UIViewAnimationCurveEaseOut,           // slow at end
         UIViewAnimationCurveLinear,
         */
        UIViewPropertyAnimator *animator = [[UIViewPropertyAnimator alloc] initWithDuration:4 curve:UIViewAnimationCurveEaseIn animations:^{
    
            redView.transform = CGAffineTransformTranslate(redView.transform, 0, 100);
            
        }];
        self.animator = animator;
    }
    
    /**
     开始动画
     */
    - (IBAction)startAnim:(UIButton *)sender {
        [self.animator startAnimation];
    }
    
    /**
     暂停动画
     */
    - (IBAction)pauseAnim:(UIButton *)sender {
        [self.animator pauseAnimation];
    }
    
    /**
     继续动画
     */
    - (IBAction)continueAnim:(UIButton *)sender {
        UISpringTimingParameters *param = [[UISpringTimingParameters alloc] initWithDampingRatio:0.1];
        [self.animator continueAnimationWithTimingParameters:param durationFactor:1];
    }
    
    /**
     停止动画
     */
    - (IBAction)stopAnim:(UIButton *)sender {
        [self.animator stopAnimation:true];
    }
    
    
    

    相关文章

      网友评论

          本文标题:iOS10中用UIViewPropertyAnimator来书写

          本文链接:https://www.haomeiwen.com/subject/eijtyttx.html