iOS10中用UIViewPropertyAnimator来书写动画

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];
}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,602评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,993评论 19 139
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,259评论 4 61
  • 现在算是什么情况? 冬天有发情期? 单身偶尔不良适应候群症。 可是我是真的不能不能绝对不能,谈恋爱。 各种不能不合...
    一只铁匠阅读 185评论 0 0
  • 日本作家东野圭吾的小说《解忧杂货店》用生活化的语言,简练地勾勒式的笔法。运用了几个片段的故事为我们精彩地描绘了一个...
    AM王的巡梦人阅读 406评论 0 1