48.核心动画之基础动画
来源:互联网 发布:免费远程监控软件 编辑:程序博客网 时间:2024/06/03 18:26
Core Animation的动画执行过程都是在后台操作的,不会阻塞主线程。
要注意的是,Core Animation是直接作用在CALayer上的,并非UIView。
keyPath:通过指定CALayer的一个属性名称为keyPath(NSString类型),并且对CALayer的这个属性的值进行修改,达到相应的动画效果。比如,指定@”position”为keyPath,就修改CALayer的position属性的值,以达到平移的动画效果
1.平移:- (void)test{ // 1. 创建核心动画 CABasicAnimation *anima = [CABasicAnimation animation] ; // 1.1告诉系统要执行什么样的动画 anima.keyPath = @"position"; // 设置通过动画将layer从哪 anima.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)]; // 到哪(到指定的位置) anima.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 300)]; //在当前位置的基础上增加多少 //anima.byValue = [NSValue valueWithCGPoint:CGPointMake(0, 300)]; // 设置动画时间 anima.duration = 5; // 1.2 设置动画执行完毕之后不删除动画 anima.removedOnCompletion = NO; // 1.3 设置保存动画的最新状态 anima.fillMode = kCAFillModeForwards; // 2.添加核心动画到Layer [self.myLayer addAnimation:anima forKey:nil];}
2.缩放:- (void)test1{ // 1. 创建核心动画 CABasicAnimation *anima = [CABasicAnimation animation] ; // 1.1设置动画类型 anima.keyPath = @"bounds"; // 1.2 设置动画执行完毕之后不删除动画 anima.removedOnCompletion = NO; // 1.3 设置保存动画的最新状态 anima.fillMode = kCAFillModeForwards; // 1.4设置动画时间 anima.duration = 1; // 1.5修改动画 anima.toValue =[NSValue valueWithCGRect: CGRectMake(0, 0, 200, 200)]; // 2.添加核心动画到Layer [self.myLayer addAnimation:anima forKey:nil];}
3.旋转:- (void)test2{ // 1. 创建核心动画 CABasicAnimation *anima = [CABasicAnimation animation] ; // 1.1设置动画类型 anima.keyPath = @"transform"; // 1.2 设置动画执行完毕之后不删除动画 anima.removedOnCompletion = NO; // 1.3 设置保存动画的最新状态 anima.fillMode = kCAFillModeForwards; // 1.4设置动画时间 anima.duration = 1; // 1.5修改动画 anima.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)]; // 2.添加核心动画到Layer [self.myLayer addAnimation:anima forKey:nil];}
4.transform动画:- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // 1. 创建核心动画 CABasicAnimation *anima = [CABasicAnimation animation] ; // 1.1设置动画类型 //anima.keyPath = @"transform.translation.x"; anima.keyPath = @"transform.scale.y"; // 1.2 设置动画执行完毕之后不删除动画 anima.removedOnCompletion = NO; // 1.3 设置保存动画的最新状态 anima.fillMode = kCAFillModeForwards; // 1.4设置动画时间 anima.duration = 1; // 1.5如何动画 //anima.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, 100, 1)]; //anima.toValue = @(100); anima.toValue = @(1.5); // 2.添加核心动画到Layer [self.myLayer addAnimation:anima forKey:nil];}
0 0
- 48.核心动画之基础动画
- 核心动画基础动画
- 核心动画(基础动画)
- iOS核心动画----基础动画
- iOS 核心动画-基础动画
- iOS 核心动画 -基础动画
- 第二部分 核心动画基础---基础动画
- 核心动画之 CAKeyframeAnimation
- 基础动画和核心动画导览
- 核心动画(2)《基础动画》
- 核心动画——基础动画
- 动画之基础动画(view动画)
- 核心动画基础动画(CABasicAnimation)关键帧动画
- iOS 动画Animation-2-1: 动画基础:核心动画简介
- iOS 动画Animation-2-2: 动画基础:核心动画
- iOS-------------核心动画之UIView动画
- 核心动画之转场动画(CATransition)
- 核心动画之基本动画CABasicAnimation
- Linux下常用的C/C++开源Socket库
- leetcode 218: The Skyline Problem
- iOS中图片拉伸技巧
- Android网络通信的六种方式示例代码
- 关于mysql数据库在运行中出现MySQL server has gone away的问题解决
- 48.核心动画之基础动画
- pg_restore - 从一个由 pg_dump 创建的备份文件中恢复 PostgreSQL 数据库。
- 1.2. chromium源代码分析 - chromiumframe - 入口函数
- 适配 - autolayout自动布局
- Java 获取计算机参数[IPvsMAC]
- Bluemix云平台实践:构建可穿戴应用(1)
- 使用log4j日志-配置加载问题
- Android中的volley_5_字节数组缓冲池ByteArrayPool 和使用缓冲池技术的自定义的PoolingByteArrayOutputStream
- 第十四周 项目一:小玩文件(1)