1,CABasicAnimation类只有三个属性:

fromValue:开始值
toValue:结束值
Duration:动画的时间
2,通过animationWithKeyPath键值对的方式设置不同的动画效果
transform.scale
transform.scale.x
transform.scale.y
transform.rotation.z
opacity
margin
zPosition
backgroundColor
cornerRadius
borderWidth
bounds
contents
contentsRect
cornerRadius
frame
hidden
mask
masksToBounds
opacity
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius
3,使用样例

(1)改变透明度动画(逐渐消失)

1
2
3
4
5
6
let animation = CABasicAnimation(keyPath: "opacity")
animation.fromValue = 1.0
animation.toValue = 0.0
animation.duration = 3.0
self.imageView.layer.addAnimation(animation, forKey: "Image-opacity")
self.imageView.alpha = 0

(2)从小变大动画(还原为默认尺寸)

1
2
3
4
5
let animation = CABasicAnimation(keyPath: "bounds.size")
animation.fromValue = NSValue(CGSize: CGSizeMake(2.0, 2.0))
animation.toValue = NSValue(CGSize: self.imageView.frame.size)
animation.duration = 3.0
self.imageView.layer.addAnimation(animation, forKey: "Image-expend")

Swift - 使用CABasicAnimation实现动画效果的更多相关文章

  1. Swift - EasingAnimation绘制圆环动画

    Swift - EasingAnimation绘制圆环动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // CircleView ...

  2. Swift - UITableView展开缩放动画

    Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...

  3. iOS开发——动画篇Swift篇&动画效果的实现

    Swift - 动画效果的实现   在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimation ...

  4. Swift - 多个mask的动画效果

    Swift - 多个mask的动画效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // TranformFadeView.swi ...

  5. Swift - 用UIScrollView实现视差动画效果

    Swift - 用UIScrollView实现视差动画效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // MoreInfoVi ...

  6. [Swift通天遁地]五、高级扩展-(11)图像加载Loading动画效果的自定义和缓存

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. Swift 带有动画效果的TabBarItem

    额...貌似挺长时间没有总结新知识了,最近在看swift,之前swift刚出来的时候大体看了一遍,后来时间长了没看加之swift2.0做了比较大的调整,公司项目也不是用swift写的,也就没怎么看了, ...

  8. swift中实现cell中局部播放的动画效果

    在cell中 // 播放器动画效果 private var replicatorLayer:ReplicatorLayer = { let layer = ReplicatorLayer.init(f ...

  9. Swift - 动画效果的实现方法总结(附样例)

    在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimations.这三个方法都是类方法. 一,使用 ...

随机推荐

  1. 图的BFS代码

    图是严蔚敏书上P168的图, 图的邻接表存储,DFS可以看以前写的文章:http://www.cnblogs.com/youxin/archive/2012/07/28/2613362.html ]; ...

  2. poj 1458 Common Subsequence(区间dp)

    题目链接:http://poj.org/problem?id=1458 思路分析:经典的最长公共子序列问题(longest-common-subsequence proble),使用动态规划解题. 1 ...

  3. mmc一维下料例子

    数据来自维基, 长度 = 5600; l切割长度= {1380, 1520, 1560, 1710, 1820, 1880, 1930, 2000, 2050, 2100, 2140,     215 ...

  4. JDBC批量运行executeBatch

    JDBC运行SQL语句,有两个处理的接口,一个PreparedStatement,Statement,一般操作JDBC比較用得多的还是PreparedStatement 只是在运行批量,Prepare ...

  5. Apple Swift 中文教程 高速參考 基本的语法

    总的来说.语法有java的味道,也有python的味道,还有swift自己的味道. 有些语法还是挺不伦不类的,不太好理解,即使你有几年的java或python经验,也不见得有些语法你能非常轻松的看明确 ...

  6. for循环语句之棋盘放粮食、百鸡百钱、纸张的折叠问题

    1.棋盘放粮食 ; ; i < ; i++) { ; ; j <= i; j++) { x = x * ; } lszl = lszl + x; } double zl = lszl * ...

  7. cURL实现get、post请求

    1.cURL介绍 cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL 的一些高级特性 ...

  8. Python-zip压缩-解压

    #打包成zip文件 import zipfile f = zipfile.ZipFile('archive.zip','w',zipfile.ZIP_DEFLATED) f.write('file_t ...

  9. Ajax 实现无刷新分页

    Ajax 实现无刷新分页

  10. 北京创客空间 BEIJING MAXPACE的小站

    北京创客空间 BEIJING MAXPACE的小站 北京市海淀区海淀大街1号中关村梦想实验室(原中关村国际数字设计中心)4层