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

2 篇文章 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)



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值