iOS 动画入门

iOS 动画入门

两个基础动画:移动和弹簧效果

1. 定义

移动:控件从一个位置移到另一个位置
弹簧效果:控件到达终点后向外扩张,但受到相反方向的弹簧牵拉。

2. 实现

  1. 位移效果

<pre><code>
override func viewDidLoad() {
ratingButtonGreat.transform = CGAffineTransformMakeTranslation(0, 600)
//将控件ratingButtonGreat移到(0,600)
}
override func viewDidAppear(animated: Bool) {
UIView.animateWithDuration(0.4, delay: 0.0, options: [], animations: {
self.ratingButtonGreat.transform = CGAffineTransformIdentity }, completion: nil)
//0.4s 后执行闭包里的代码,CGAffineTransformIdentity 代表设计时这个控件的位置
</pre></code>

  1. 弹簧效果
    前面同1
    只是将
    <pre><code>
    UIView.animateWithDuration(0.4, delay: 0.0, options: [], animations: {
    </pre></code>
    换成
    <pre><code>
    UIView.animateWithDuration(0.4, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.3, options: [], animations: {
    </pre></code>

即可
其中usingSpringWithDamping代表弹簧劲度系数(0~1)
initialSpringVelocity代表向外弹出的初速度(0~1)

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

推荐阅读更多精彩内容