使用CABasicAnimation的时候 总会遇到 animationWithKeyPath的情况 keyPath到底是什么呢?
今天查了下文档,大概意思是说使用此动画的对象 的key (也就是这个使用动画的对象能响应个消息)。
其中尝试对backgroundColor进行设置
旋转于放大缩小使用transform
补充1:
keypath 是 layer属性 注释说明中含有Animatable的
资料:http://objccn.io/issue-12-4/
资料:http://blog.csdn.net/lvxiangan/article/details/17167827
// // PLLViewController.m // LNCAnimation // // Created by liu poolo on 14-5-13. // Copyright (c) 2014年 liu poolo. All rights reserved. // #import "PLLViewController.h" #import <QuartzCore/QuartzCore.h> @interface PLLViewController () @end @implementation PLLViewController - (void)viewDidLoad { [super viewDidLoad]; CALayer *_cl=[[CALayer alloc] init]; _cl.backgroundColor=[[UIColor grayColor] CGColor]; _cl.frame=CGRectMake(10, 10, 40, 40); _cl.cornerRadius=5.0f; CABasicAnimation *_ca=[CABasicAnimation animationWithKeyPath:@"position"];//对哪个通道进行动画描写 _ca.fromValue=[NSValue valueWithCGPoint:_cl.position]; CGPoint toPoint=_cl.position; toPoint.x+=100; _ca.toValue=[NSValue valueWithCGPoint:toPoint]; [self.view.layer addSublayer:_cl]; _ca.autoreverses=YES; _ca.duration=1.0f; _ca.repeatCount=NSNotFound; // [_cl addAnimation:_ca forKey:@"kLayerPLMove"]; CABasicAnimation *_caRotato = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"]; _caRotato.fromValue = [NSNumber numberWithFloat:0.0f]; _caRotato.toValue = [NSNumber numberWithFloat:6.0f*M_PI]; _caRotato.autoreverses=YES; _caRotato.duration=10.0f; _caRotato.repeatCount=NSNotFound; CABasicAnimation *_caScaole = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"]; _caScaole.fromValue = [NSNumber numberWithFloat:1.0f]; _caScaole.toValue = [NSNumber numberWithFloat:3.0f]; _caScaole.autoreverses=YES; _caScaole.duration=10.0f; _caScaole.repeatCount=NSNotFound; CABasicAnimation *_caColor=[CABasicAnimation animationWithKeyPath:@"backgroundColor"]; //animationWithKeyPath后跟随的是CALayer可接受的Key即可 既使用动画的对象的Key _caColor.fromValue=(__bridge id)([[UIColor grayColor] CGColor]); _caColor.toValue=(__bridge id)([[UIColor redColor] CGColor]); CAAnimationGroup *_caGroup=[CAAnimationGroup animation]; [_caGroup setAnimations:[NSArray arrayWithObjects:_ca,_caRotato,_caScaole,_caColor,nil]]; _caGroup.duration=10.0f; _caGroup.repeatCount=NSNotFound; _caGroup.autoreverses=YES; [_cl addAnimation:_caGroup forKey:@"GroupKey"]; // [_cl addAnimation:_caRotato forKey:@"rotatoKey"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关推荐
GMTC全球移动技术大会ppt 作者:美团大众点评 高级工程师 罗泽响 主题:美团 iOS 客户端的构建思考与实践
IOS_CA路由CA认证服务器,IOS_CA路由CA认证服务器
IOS开发
美团 iOS 客户端的构建思考与实践 罗泽响 .pdf
iOS动画效果集 CA360 ,CA360 包含 iOS 上的 Core Animation 的非常多的示例。
一个简单的ios翻页效果,用core animation实现
location驱动ios12.4 ios12.3 ios12.2 ios12.1 ios12.0 ios11.0 ios11.4
思考网络设备交换机sw2960的最新的IOS版本
ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧...
iOS开发中一些手写控件及其相关属性的使用
iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16...
iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS ...
ios 录屏开发 支持 ios9 ios10 ios11
很逼真的一个树叶动画,因为不会传动图...希望见谅 ...仿照的一个树叶飘落动画,在原来的基础上添加了一些新的效果,并且添加了很多代码注释,希望刚接触CA的朋友们能快速上手并使用CA动画,享受带来的乐趣
iOS 10 App Development Essentials: Learn to Develop iOS 10 Apps with Xcode 8 and Swift 3 Author: Neil Smyth Length: 816 pages Edition: 1 Language: English Publisher: CreateSpace Independent Publishing...
HBuilderX申请iOS证书在线打包iOS文档,介绍iOS证书的申请及打包过程!
iOS开发之使用画板和CA自定义有动画效果的AlertView完整 代码
iOS开发用到的一些书籍