Core Animation - 属性动画CAPropertyAnimation
来源:互联网 发布:手机测音软件 编辑:程序博客网 时间:2024/05/21 14:04
core animation里面有个很重要的类CAPropertyAnimation,它有两个子类,CABasicAnimation和CAKeyFrameAnimation。
类图如下:
CABasicAnimation可以设置一些属性,比如位置从A到B,然后就会移动过去。
CAKeyFrameAnimation基本就和flash里面说的补间动画一样(tweening),设置一些值,比如A,B,C,D4个位置,然后A和B之间,会根据一定的算法不一些位置。
应该说CAKeyFrameAnimation会比CABasicAnimation高级智能一些,动画看起来也会更加平滑一点。
具体使用都是很简单,下面有个例子,创建了关键帧动画和基本动画:
CALayer *sublayer =[CALayer layer]; sublayer.backgroundColor =[UIColor orangeColor].CGColor; sublayer.shadowOffset = CGSizeMake(0, 3); sublayer.shadowRadius =5.0; sublayer.shadowColor =[UIColor blackColor].CGColor; sublayer.shadowOpacity = 1; sublayer.borderColor =[UIColor blackColor].CGColor; sublayer.borderWidth =2.0; sublayer.cornerRadius =10.0; sublayer.anchorPoint = CGPointMake(0, 0); [self.view.layer addSublayer:sublayer]; CGImageRef img = [UIImage imageNamed:@"Image"].CGImage; sublayer.contents = (__bridge id)img; sublayer.frame = CGRectMake(180, 60, CGImageGetWidth(img), CGImageGetWidth(img)); CGPoint fromPoint = sublayer.frame.origin; //路径曲线 UIBezierPath *movePath = [UIBezierPath bezierPath]; [movePath moveToPoint:fromPoint]; CGPoint toPoint = CGPointMake(30, 360); [movePath addQuadCurveToPoint:toPoint controlPoint:CGPointMake(300,0)]; //关键帧 CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; moveAnim.path = movePath.CGPath; moveAnim.removedOnCompletion = YES; moveAnim.duration = 3; moveAnim.delegate = self; //旋转变化 CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"]; scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; //x,y轴缩小到0.1,Z 轴不变 scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]; scaleAnim.removedOnCompletion = YES; scaleAnim.duration = 5; scaleAnim.delegate = self; //透明度变化 CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"]; opacityAnim.fromValue = [NSNumber numberWithFloat:1.0]; opacityAnim.toValue = [NSNumber numberWithFloat:0.1]; opacityAnim.removedOnCompletion = YES; opacityAnim.delegate = self;
上面的代码里面有一个关键帧动画和两个基本动画,直接把它们add到CALayer就可以了。
0 0
- Core Animation - 属性动画CAPropertyAnimation
- 动画 Core Animation 直接修改视图属性
- core animation初识之属性动画
- Core Animation 动画
- Core Animation CALayer动画
- ios Core Animation 动画
- 核心动画Core Animation
- Core Animation动画技术
- Core Animation 核心动画
- 核心动画(Core Animation)
- 核心动画 Core Animation
- 核心动画(Core Animation)
- Core Animation 动画
- Core Animation核心动画
- Core Animation动画概述
- Core Animation - 核心动画
- 核心动画Core Animation
- Core Animation(核心动画)
- Android实现计时与倒计时的几种方法
- 基于web的AssetBundle的研究
- Python核心编程(第二版)一些习题答案心得
- Google Guava 库用法整理
- 分库分表
- Core Animation - 属性动画CAPropertyAnimation
- Google Guava官方教程(中文版)
- 基于文件传输的UDP协议分析(1)
- 软件测试中的语句覆盖,分支覆盖,条件覆盖以及路径覆盖
- 码农场 » POJ 3421 X-factor Chains 题解 《挑战程序设计竞赛》
- 正确理解SOA、SaaS和云计算之间的关系
- 迟到的开始
- 线程安全的List集合(性能比较差..)
- mysql触发器