关闭

[iOS]UIView动画学习笔记(下)

标签: iosuiview动画
261人阅读 评论(0) 收藏 举报
分类:

上一篇文章记录了几类简单的动画内容,下面我们继续学习更多的动画,
慕课网视频的链接如下:
http://www.imooc.com/learn/395

本文涉及的内容:
- Repeat
- Easing
- Spring

下面我们分别介绍:

Repeat

可以让动画来回动作

override func viewDidAppear(animated: Bool){
    super.viewDidAppear(animated)
    UIView.animateWithDuration(1, animations:{
        self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
    })
    UIView.animateWithDuration(1, delay:0, options: .Repeat, animations:{
        self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
    }, completion: nil)
    UIView.animateWithDuration(1, delay:0, options: .Repeat | .Autoreverse, animations:{
        self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
    }, completion: nil)

}

Easing

这里写图片描述

Easing动画涉及贝塞尔曲线,贝塞尔曲线绘制可以参考如下网址:
http://cubic-bezier.com/
http://easings.net/zh-cn

实现方式如下:

override func viewDidAppear(animated: Bool){
    super.viewDidAppear(animated)
    UIView.animateWithDuration(1, animations:{
        self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
    })
    UIView.animateWithDuration(1, delay:0, options: .CurveEaseIn, animations:{
        self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
    }, completion: nil)
    UIView.animateWithDuration(1, delay:0, options: .CurveEaseOut, animations:{
        self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
    }, completion: nil)
    UIView.animateWithDuration(1, delay:0, options: .CurveEaseInOut, animations:{
        self.yelloSquare.center.x = self.view.bounds.width - self.yelloSquare.center.x
    }, completion: nil)

}

Spring

这里写图片描述

Spring弹簧动画使用的API的参数更多,原型如下:

//只有iOS7以上才支持
UIView.animateWithDuration(duration: NSTimeInterval, 
                           delay: NSTimeInterval,
                           usingSpringWithDamping: CGFloat,
                           initailSpringVelocity: CGFloat,
                           options: UIViewAnimationOptions,
                           animations: () -> Void,
                           completion: ((Bool) -> Void)?)

应用如下:

override func viewDidAppear(animated: Bool){
    super.viewDidAppear(animated)
    UIView.animateWithDuration(1, animations:{
        self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
    })
    UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.5, initailSpringVelocity: 0, options: nil, animations:{
        self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
},completion: nil)

    UIView.animateWithDuration(5, delay: 0, usingSpringWithDamping:0.3, initailSpringVelocity: 1, options: nil, animations:{
        self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
},completion: nil)



}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14422次
    • 积分:445
    • 等级:
    • 排名:千里之外
    • 原创:31篇
    • 转载:2篇
    • 译文:0篇
    • 评论:4条
    文章分类
    最新评论