Swift3.0为视图添加旋转动画_CABasicAnimation
2024-08-31 03:51:47
Swift2.3:
//创建旋转动画
let anim = CABasicAnimation(keyPath: "transform.rotation")
//旋转角度
anim.toValue = 1 * M_PI
//旋转指定角度需要的时间
anim.duration = 1
//旋转重复次数
anim.repeatCount = MAXFLOAT
//动画执行完后不移除
anim.removedOnCompletion = true
//将动画添加到视图的laye上
view.layer.addAnimation(anim, forKey: nil)
//取消动画
view.layer.removeAllAnimations()
//这个是旋转方向的动画
UIView.animateWithDuration(0.2) { () -> Void in
//指定旋转角度是180°
view.transform = CGAffineTransformRotate(view.transform, CGFloat(M_PI))
}
Swift3.0:
let anim = CABasicAnimation(keyPath: "transform.rotation")
anim.toValue = 1 * M_PI
anim.duration = 1
anim.repeatCount = MAXFLOAT
anim.isRemovedOnCompletion = true
view1.layer.add(anim, forKey: nil)
view1.layer.removeAllAnimations()
UIView.animate(withDuration: 0.2) {
view1.transform = view1.transform.rotated(by: CGFloat(M_PI))
}
最新文章
- MongoDB-基础-limit-skip-sort
- STL set 用法
- 【笔记】js Function类型 内部方法callee
- Linux下多路径multipath配置
- [BZOJ4530][Bjoi2014]大融合 LCT + 启发式合并
- typedef和#define
- 非常实用的10个PHP高级应用技巧
- [POJ1236]Network of Schools(并查集+floyd,伪强连通分量)
- (转载)PHP去掉转义后字符串中的反斜杠\函数stripslashes
- 使用WMI控制Windows进程 和服务
- Python网络02 Python服务器进化
- mysql函数二
- linux查看系统负载
- IOS 看懂此文,你的block再也不需要WeakSelf弱引用了!
- Python“函数式编程”中常用的函数
- Python importlib 动态加载模块
- noip第18课资料
- NSArray与NSString、NSData,NSDictionary与NSString、NSData 相互转化
- docker 安全性问题
- 构建NDK交叉编译链
热门文章
- lastb---显示用户错误的登录列表
- kill&;&;pkill&;&;killall---删除执行中的程序
- git- 仓库创建、修改、提交、撤销
- dom4j解析xml文件和字符串
- HttpClient的基本使用
- ontouch、dispatchtouchevent、interceptouchevent-相关事件
- Docker安装RabbitMQ,RabbitMQ Management使用
- Invalid property 'annotatedClasses' of bean class
- 解决Keystore was tampered with, or password was incorrect
- Dynamics CRM2016 Web API之Expand related entities &;amp; $ref &;amp; $count