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

2 篇文章 0 订阅

本文是学习慕课网UIView动画的笔记,可用于简单的创建动画,
慕课网视频链接如下:
http://www.imooc.com/learn/392

通过使用动画,我们可以使我们的iOS App更加生动,提高用户体验和粘性。
通常,我们的动画是在页面刚刚显示(viewDidAppear)或者点击了某个按键(Action)的时候开始,持续一小段时间结束

使用的API是:

Void UIView.animateWithDuration(duration:NSTimeInterval, animations: () -> Void)

当然还有很多变体的方法,当我们在Xcode输入函数名的时候,都可以展现出来,包括延迟执行和执行完成后,还可以调用另一个closure

我们的比较初级的动画效果分为如下几类:
- 位置
- 透明度
- 大小
- 颜色
- 翻转

下面我们依次进行说明:

位置

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.5, options: nil, animations:{
        self.redSquare.center.y = self.view.bounds.height - self.redSquare.center.y
    }, completion: nil)
    UIView.animateWithDuration(1, delay:0.5, options: nil, animations:{
        self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
        self.greenSquare.center.y = self.view.bounds.height - self.greenSquare.center.y
    }, completion: nil)

}

透明度(Opacity)

override func viewDidAppear(animated: Bool){
    super.viewDidAppear(animated)
    UIView.animateWithDuration(1, animations:{
        self.blueSquare.alpha = 0.1
    })  
}

大小

override func viewDidAppear(animated: Bool){
    super.viewDidAppear(animated)
    UIView.animateWithDuration(1, animations:{
        self.blueSquare.transform = CGAffineTransformMakeScale(2.0,2.0)
    })  
}

颜色

override func viewDidAppear(animated: Bool){
    super.viewDidAppear(animated)
    UIView.animateWithDuration(1, animations:{
        self.blueSquare.backgroundColor = UIColor.redColor()
        self.label.textColor = UIColor.whiteColor()
    })  
}

翻转

override func viewDidAppear(animated: Bool){
    super.viewDidAppear(animated)
    UIView.animateWithDuration(1, animations:{
        self.blueSqure.transform = CGAffineTransformRotation(CGFloat(M_PI))
    })  
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值