核心动画
来源:互联网 发布:纳粹德国知乎 编辑:程序博客网 时间:2024/06/05 17:44
iOS提供了相应的核心动画类CABasicAnimation,CAKeyframeAnimation,我们可以通过设置这些类的相关属性来实现我们所需要的动画效果
首先,创建一个做动画的UIView
var myView = UIView()myView.frame = CGRect(x: self.view.center.x - 100,y: 200,width: 200,height: 200) myView.backgroundColor = UIColor.green self.view.addSubview(myView)
设置CABasicAnimation动画
//缩放动画 let scaleAnimate = CABasicAnimation(keyPath: "transform.scale") //起始帧 scaleAnimate.fromValue = 1.0 //结束帧 scaleAnimate.toValue = 1.5 //回放动画 scaleAnimate.autoreverses = true //动画次数 scaleAnimate.repeatCount = MAXFLOAT //动画时间 scaleAnimate.duration = 1.0 //旋转动画 let opaqueAnimate = CABasicAnimation(keyPath:"transform.rotation") opaqueAnimate.fromValue = 0 opaqueAnimate.toValue = Double.pi * 2 opaqueAnimate.autoreverses = true opaqueAnimate.repeatCount = MAXFLOAT opaqueAnimate.duration = 1.0 //添加动画 myView.layer.add(scaleAnimate, forKey: "scaleAnimate") myView.layer.add(opaqueAnimate, forKey: "rotationAnimate")
设置CAKeyframeAnimation动画
let keyAnimate = CAKeyframeAnimation(keyPath: "position") //设置关键帧,动画的轨迹 let value0 = NSValue(cgPoint: myView.layer.position) let value1 = NSValue(cgPoint: CGPoint(x: myView.layer.position.x, y: myView.layer.position.y + 200)) let value2 = NSValue(cgPoint: CGPoint(x: myView.layer.position.x - 150, y: myView.layer.position.y + 200)) let value3 = NSValue(cgPoint: CGPoint(x: myView.layer.position.x - 150, y: myView.layer.position.y)) let value4 = NSValue(cgPoint: myView.layer.position)keyAnimate.values = [value0, value1, value2, value3, value4] keyAnimate.autoreverses = false keyAnimate.repeatCount = MAXFLOAT keyAnimate.duration = 6.0 myView.layer.add(keyAnimate, forKey: "keyAnimate")
运行结果
阅读全文
0 0
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 核心动画
- 深入理解Java迭代器
- jenkins selenium 不显示浏览器 解决办法
- centos7 minimal virtualbox下无法联网问题
- MFC程序链接
- error C2375 重定义错误的解决方式,Winsock2.h
- 核心动画
- myeclipse10中maven项目maven test报错:-Dmaven.multiModuleProjectDirectory system property is not set.原因
- C/C++——简单游戏框架
- PCI-E 1x, 4x, 8x, 16x 接口定义
- JDK安装和环境变量配置
- 初学Linux,首先需要弄清Linux 标准目录结构
- JavaScript的闭包问题
- iText导出pdf、word、图片
- C++内存分配秘籍—new,malloc,GlobalAlloc详解