[iOS]UIView动画学习笔记(上)
2015-07-09 12:13
453 查看
本文是学习慕课网UIView动画的笔记,可用于简单的创建动画,
慕课网视频链接如下:
http://www.imooc.com/learn/392
通过使用动画,我们可以使我们的iOS App更加生动,提高用户体验和粘性。
通常,我们的动画是在页面刚刚显示(viewDidAppear)或者点击了某个按键(Action)的时候开始,持续一小段时间结束
使用的API是:
当然还有很多变体的方法,当我们在Xcode输入函数名的时候,都可以展现出来,包括延迟执行和执行完成后,还可以调用另一个closure
我们的比较初级的动画效果分为如下几类:
- 位置
- 透明度
- 大小
- 颜色
- 翻转
下面我们依次进行说明:
慕课网视频链接如下:
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)) }) }
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- php判断GIF图片是否为动画的方法
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- jQuery动画特效实例教程
- JQuery动画和停止动画实例代码
- JQuery动画与特效实例分析
- Jquery 自定义动画概述及示例
- 基于jquery的动画效果代码
- 锋利的jQuery 要点归纳(三) jQuery中的事件和动画(上:事件篇)
- 基于Jquery的温度计动画效果
- js判断客户端是iOS还是Android等移动终端的方法