IOS动画开发总结

15 篇文章 0 订阅

iOS开发动画(Animation)总结

http://blog.csdn.net/mad2man/article/details/17554621


UIView的,翻转、旋转,偏移,翻页,缩放,取反的动画效果


翻转的动画
//开始动画  
   [UIView beginAnimations:@"doflip" context:nil];  
   //设置时常  
   [UIView setAnimationDuration:1];  
   //设置动画淡入淡出  
   [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
   //设置代理  
   [UIView setAnimationDelegate:self];  
   //设置翻转方向  
   [UIView setAnimationTransition:  
   UIViewAnimationTransitionFlipFromLeft  forView:manImageView cache:YES];  
   //动画结束  
   [UIView commitAnimations];  

旋转动画
//创建一个CGAffineTransform  transform对象  
CGAffineTransform  transform;   
//设置旋转度数  
transform = CGAffineTransformRotate(manImageView.transform,M_PI/6.0);  
//动画开始  
[UIView beginAnimations:@"rotate" context:nil ];  
//动画时常  
[UIView setAnimationDuration:2];  
//添加代理  
[UIView setAnimationDelegate:self];  
//获取transform的值  
[manImageView setTransform:transform];  
//关闭动画  
[UIView commitAnimations];  

偏移动画
    [UIView beginAnimations:@"move" context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationDelegate:self];
    //改变它的frame的x,y的值
    manImageView.frame=CGRectMake(100,100, 120,100);
    [UIView commitAnimations];


翻页动画
[UIView beginAnimations:@"curlUp" context:nil];  
  [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//指定动画曲线类型,该枚举是默认的,线性的是匀速的  
  //设置动画时常  
  [UIView setAnimationDuration:1];  
  [UIView setAnimationDelegate:self];  
   //设置翻页的方向  
  [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:manImageView cache:YES];  
  //关闭动画  
  [UIView commitAnimations];  


缩放动画
CGAffineTransform  transform;  
transform = CGAffineTransformScale(manImageView.transform,1.2,1.2);  
[UIView beginAnimations:@"scale" context:nil];  
[UIView setAnimationDuration:2];  
[UIView setAnimationDelegate:self];  
[manImageView setTransform:transform];  
[UIView commitAnimations];  

取反的动画效果是根据当前的动画取他的相反的动画

CGAffineTransform transform;  
   transform=CGAffineTransformInvert(manImageView.transform);  
     
   [UIView beginAnimations:@"Invert" context:nil];  
   [UIView setAnimationDuration:2];//动画时常  
   [UIView setAnimationDelegate:self];  
   [manImageView setTransform:transform];//获取改变后的view的transform  
   [UIView commitAnimations];//关闭动画  

========

IOS开发-UIView之动画效果的实现方法(合集)

http://www.tuicool.com/articles/BjMrQne
原文  http://www.cnblogs.com/GarveyCalvin/p/4193963.html
主题 UIView
前言:在开发APP中,我们会经常使用到动画效果。使用动画可以让我们的APP更酷更炫,最重要的是优化用户体验,但取决于动画的质量。像QQ、微信、新浪微博等APP,动画效果就很好了,至少我很喜欢它们的动画,让我使用起来感觉很顺畅,心情很开朗。本文会介绍UIView效果的实现方法,非核心动画。


一、使用UIView类实现动画

基本写法,代码必须放在Begin和Commit之间:

[UIView beginAnimations:nil context:nil]; // 开始动画
// Code...
[UIView commitAnimations]; // 提交动画
简单例子:

[UIView beginAnimations:nil context:nil]; // 开始动画
[UIView setAnimationDuration:10.0]; // 动画时长

/**
 *  图像向下移动
 */
CGPoint point = _imageView.center;
point.y += 150;
[_imageView setCenter:point];


[UIView commitAnimations]; // 提交动画
同时运行多个动画效果:


[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0];
[_imageView setAlpha:0.0];
[UIView commitAnimations];


[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0];
CGPoint point = _imageView.center;
point.y += 150;
[_imageView setCenter:point];
[UIView commitAnimations];
以上代码实现的动画效果为( 同时执行 ):


1、图像向下平移150像像


2、设置图像透明度为0。


指定上下文:


CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:2.0];
[_imageView setAlpha:0];
[UIView commitAnimations];
UIGraphicsGetCurrentContext():获取当前视图的上下文


其它方法及属性:

以下方法及属性不为全部,只例举部分(其它没提及到的方法及属性请自行尝试,谢谢):

// 开始动画
+ (void)beginAnimations:(NSString *)animationID context:(void *)context;

// 提交动画
+ (void)commitAnimations; 

// 设置动画曲线,默认是匀速进行:
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve;


// 设置动画时长:
+ (void)setAnimationDuration:(NSTimeInterval)duration;
 
// 默认为YES。为NO时跳过动画效果,直接跳到执行后的状态。
+ (void)setAnimationsEnabled:(BOOL)enabled;

// 设置动画延迟执行(delay:秒为单位):
+ (void)setAnimationDelay:(NSTimeInterval)delay;
 
// 动画的重复播放次数
+ (void)setAnimationRepeatCount:(float)repeatCount;

// 如果为YES,逆向(相反)动画效果,结束后返回动画逆向前的状态; 默认为NO:
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses;


// 设置动画代理:
+ (void)setAnimationDelegate:(id)delegate;
 
// 动画将要开始时执行方法××(必须要先设置动画代理):
+ (void)setAnimationWillStartSelector:(SEL)selector;

// 动画已结束时执行方法××(必须要先设置动画代理):
+ (void)setAnimationDidStopSelector:(SEL)selector;

/**
 *  设置动画过渡效果
 *
 *  @param transition 动画的过渡效果
 *  @param view 过渡效果作用视图
 *  @param cache 如果为YES,开始和结束视图分别渲染一次并在动画中创建帧;否则,视图将会渲染每一帧。例如,你不需要在视图转变中不停的更新,你只需要等到转换完成再去更新视图。
 */
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;

// 删除所有动画层
// 注意:层指的是layout,例:[_imageView.layer removeAllAnimations];
- (void)removeAllAnimations;
二、使用UIView的动画块代码:

方法一:

[UIView animateWithDuration:4.0 // 动画时长
                 animations:^{
                     // code
                 }];
方法二:

[UIView animateWithDuration:4.0 // 动画时长
         animations:^{
           // code...
         }
         completion:^(BOOL finished) {
           // 动画完成后执行
           // code...
         }];
方法三:

[UIView animateWithDuration:4.0 // 动画时长
            delay:2.0 // 动画延迟
          options:UIViewAnimationOptionCurveEaseIn // 动画过渡效果
         animations:^{
           // code...
         }
         completion:^(BOOL finished) {
           // 动画完成后执行
           // code...
         }];
方法四,Spring Animationring Animation):

在IOS7开始,系统动画效果广泛应用Spring Animation :

[UIView animateWithDuration:4.0 // 动画时长
            delay:0.0 // 动画延迟
   usingSpringWithDamping:1.0 // 类似弹簧振动效果 0~1
    initialSpringVelocity:5.0 // 初始速度
          options:UIViewAnimationOptionCurveEaseInOut // 动画过渡效果
         animations:^{
           // code...
           CGPoint point = _imageView.center;
           point.y += 150;
           [_imageView setCenter:point];
         } completion:^(BOOL finished) {
           // 动画完成后执行
           // code...
           [_imageView setAlpha:1];
         }];
usingSpringWithDamping:它的范围为 0.0f 到 1.0f ,数值越小「弹簧」的振动效果越明显。

initialSpringVelocity:初始的速度,数值越大一开始移动越快。值得注意的是,初始速度取值较高而时间较短时,也会出现反弹情况。

转:Spring Animation 是线性动画或 ease-out 动画的理想替代品。由于 iOS 本身大量使用的就是 Spring Animation,用户已经习惯了这种动画效果,因此使用它能使 App 让人感觉更加自然,用 Apple 的话说就是「instantly familiar」。此外,Spring Animation 不只能对位置使用,它适用于所有可被添加动画效果的属性。
方法五,关键帧动画:

UIView动画已经具备高级的方法来创建动画,而且可以更好地理解和构建动画。IOS7以后苹果新加了一个animateKeyframesWithDuration的方法,我们可以使用它来创建更多更复杂更酷炫的动画效果,而不需要去使用到核心动画(CoreAnimatino)。
创建关键帧方法:

/**
 *  添加关键帧方法
 *
 *  @param duration   动画时长
 *  @param delay      动画延迟
 *  @param options    动画效果选项
 *  @param animations 动画执行代码
 *  @param completion 动画结束执行代码
 */
+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration
                               delay:(NSTimeInterval)delay
                             options:(UIViewKeyframeAnimationOptions)options
                          animations:(void (^)(void))animations
                          completion:(void (^)(BOOL finished))completion;
添加关键帧方法:

/**
 *  添加关键帧
 *
 *  @param frameStartTime 动画相对开始时间
 *  @param frameDuration  动画相对持续时间
 *  @param animations     动画执行代码
 */
+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime
                        relativeDuration:(double)frameDuration
                              animations:(void (^)(void))animations;
以上说的相对时间,也就是说:“它们自身会根据动画总持续时长自动匹配其运行时长”。

下面用一个简单的示例作解答,彩虹变化视图:

void (^keyFrameBlock)() = ^(){
    // 创建颜色数组
    NSArray *arrayColors = @[[UIColor orangeColor],
      [UIColor yellowColor],
      [UIColor greenColor],
      [UIColor blueColor],
      [UIColor purpleColor],
      [UIColor redColor]];
    NSUInteger colorCount = [arrayColors count];
    // 循环添加关键帧
    for (NSUInteger i = 0; i < colorCount; i++) {
        [UIView addKeyframeWithRelativeStartTime:i / (CGFloat)colorCount
         relativeDuration:1 / (CGFloat)colorCount
               animations:^{
                   [_graduallyView setBackgroundColor:arrayColors[i]];
               }];
    }
};
[UIView animateKeyframesWithDuration:4.0
        delay:0.0
      options:UIViewKeyframeAnimationOptionCalculationModeCubic | UIViewAnimationOptionCurveLinear
   animations:keyFrameBlock
   completion:^(BOOL finished) {
       // 动画完成后执行
       // code...
   }];
动画过渡效果(Options),新增了以下几个:

UIViewKeyframeAnimationOptionCalculationModeLinear     = 0 << 10, // default
UIViewKeyframeAnimationOptionCalculationModeDiscrete   = 1 << 10,
UIViewKeyframeAnimationOptionCalculationModePaced      = 2 << 10,
UIViewKeyframeAnimationOptionCalculationModeCubic      = 3 << 10,
UIViewKeyframeAnimationOptionCalculationModeCubicPaced = 4 << 10
下面我们看一张图,让我们更容易理解:


小结:

UIView实现动画的方法有很多种。简单的动画效果你可以随意丢,比较复杂的动画效果你可以选用关键帧KeyFrame方法。

至于选用哪种,就需要根据产品需求去进行判断。

本文参考文章:

http://www.tuicool.com/articles/FjiQJbF

http://www.tuicool.com/articles/ZR7nYv
========

iOS开发UI篇—核心动画(基础动画)

http://www.cnblogs.com/wendingding/p/3801157.html


一、简单介绍


CAPropertyAnimation的子类


属性解析:

fromValue:keyPath相应属性的初始值

toValue:keyPath相应属性的结束值

随着动画的进行,在长度为duration的持续时间内,keyPath相应属性的值从fromValue渐渐地变为toValue

如果fillMode=kCAFillModeForwards和removedOnComletion=NO,那么在动画执行完毕后,图层会保持显示动画执行后的状态。但在实质上,图层的属性值还是动画执行前的初始值,并没有真正被改变。

比如,CALayer的position初始值为(0,0),CABasicAnimation的fromValue为(10,10),toValue为(100,100),虽然动画执行完毕后图层保持在(100,100)这个位置,实质上图层的position还是为(0,0)

 
二、平移动画

代码示例:


 //
 //  YYViewController.m
 //  07-核心动画(基础动画)
 //
 //  Created by apple on 14-6-21.
 //  Copyright (c) 2014年 itcase. All rights reserved.
 //
 
 #import "YYViewController.h"

@interface YYViewController ()
@property(nonatomic,strong)CALayer *myLayer;
@end

@implementation YYViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //创建layer
    CALayer *myLayer=[CALayer layer];
    //设置layer的属性
    myLayer.bounds=CGRectMake(0, 0, 50, 80);
    myLayer.backgroundColor=[UIColor yellowColor].CGColor;
    myLayer.position=CGPointMake(50, 50);
    myLayer.anchorPoint=CGPointMake(0, 0);
    myLayer.cornerRadius=20;
    //添加layer
    [self.view.layer addSublayer:myLayer];
    self.myLayer=myLayer;
}

//设置动画(基础动画)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.创建核心动画
    //    CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:<#(NSString *)#>]
    CABasicAnimation *anima=[CABasicAnimation animation];
    
    //1.1告诉系统要执行什么样的动画
    anima.keyPath=@"position";
    //设置通过动画,将layer从哪儿移动到哪儿
    anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
    anima.toValue=[NSValue valueWithCGPoint:CGPointMake(200, 300)];
    
    //1.2设置动画执行完毕之后不删除动画
    anima.removedOnCompletion=NO;
    //1.3设置保存动画的最新状态
    anima.fillMode=kCAFillModeForwards;

    //2.添加核心动画到layer
   [self.myLayer addAnimation:anima forKey:nil];

}
  @end

代码说明:

 第42行设置的keyPath是@"position",说明要修改的是CALayer的position属性,也就是会执行平移动画

 第44,45行,这里的属性接收的时id类型的参数,因此并不能直接使用CGPoint这种结构体类型,而是要先包装成NSValue对象后再使用。

 默认情况下,动画执行完毕后,动画会自动从CALayer上移除,CALayer又会回到原来的状态。为了保持动画执行后的状态,可以加入第48,50行代码

byValue和toValue的区别,前者是在当前的位置上增加多少,后者是到指定的位置。
 
执行效果:

设置代理:设置动画的代理,可以监听动画的执行过程,这里设置控制器为代理。

代码示例:

#import "YYViewController.h"

@interface YYViewController ()
@property(nonatomic,strong)CALayer *myLayer;
@end

@implementation YYViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
   
    //创建layer
    CALayer *myLayer=[CALayer layer];
    //设置layer的属性
    myLayer.bounds=CGRectMake(0, 0, 50, 80);
    myLayer.backgroundColor=[UIColor yellowColor].CGColor;
    myLayer.position=CGPointMake(50, 50);
    myLayer.anchorPoint=CGPointMake(0, 0);
    myLayer.cornerRadius=20;
    //添加layer
    [self.view.layer addSublayer:myLayer];
    self.myLayer=myLayer;
}

//设置动画(基础动画)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.创建核心动画
    //    CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:<#(NSString *)#>]
    CABasicAnimation *anima=[CABasicAnimation animation];
    
    //1.1告诉系统要执行什么样的动画
    anima.keyPath=@"position";
    //设置通过动画,将layer从哪儿移动到哪儿
   anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
    anima.toValue=[NSValue valueWithCGPoint:CGPointMake(200, 300)];
    
    //1.2设置动画执行完毕之后不删除动画
    anima.removedOnCompletion=NO;
    //1.3设置保存动画的最新状态
    anima.fillMode=kCAFillModeForwards;
    anima.delegate=self;
    //打印
    NSString *str=NSStringFromCGPoint(self.myLayer.position);
    NSLog(@"执行前:%@",str);
    
    //2.添加核心动画到layer
    [self.myLayer addAnimation:anima forKey:nil];

}

-(void)animationDidStart:(CAAnimation *)anim
{
    NSLog(@"开始执行动画");
}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    //动画执行完毕,打印执行完毕后的position值
    NSString *str=NSStringFromCGPoint(self.myLayer.position);
    NSLog(@"执行后:%@",str);
}

@end

打印position的属性值,验证图层的属性值还是动画执行前的初始值{50,50},并没有真正被改变为{200,300}。


三、缩放动画


实现缩放动画的代码示例:


复制代码
 1 //
 2 //  YYViewController.m
 3 //  08-核心动画平移
 4 //
 5 //  Created by apple on 14-6-21.
 6 //  Copyright (c) 2014年 itcase. All rights reserved.
 7 //
 8 
 9 #import "YYViewController.h"
10 
11 @interface YYViewController ()
12 @property(nonatomic,strong)CALayer *myLayer;
13 @end
14 
15 @implementation YYViewController
16 
17 - (void)viewDidLoad
18 {
19     [super viewDidLoad];
20     
21     //创建layer
22     CALayer *myLayer=[CALayer layer];
23     //设置layer的属性
24     myLayer.bounds=CGRectMake(0, 0, 150, 60);
25     myLayer.backgroundColor=[UIColor yellowColor].CGColor;
26     myLayer.position=CGPointMake(50, 50);
27     myLayer.anchorPoint=CGPointMake(0, 0);
28     myLayer.cornerRadius=40;
29     //添加layer
30     [self.view.layer addSublayer:myLayer];
31     self.myLayer=myLayer;
32 }
33 
34 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
35 {
36     //1.创建动画
37     CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:@"bounds"];
38     //1.1设置动画执行时间
39     anima.duration=2.0;
40     //1.2设置动画执行完毕后不删除动画
41     anima.removedOnCompletion=NO;
42     //1.3设置保存动画的最新状态
43     anima.fillMode=kCAFillModeForwards;
44     //1.4修改属性,执行动画
45     anima.toValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
46     //2.添加动画到layer
47     [self.myLayer addAnimation:anima forKey:nil];
48 }
49 
50 @end
复制代码
实现效果:


  


四、旋转动画


代码示例:


复制代码
 1 //
 2 //  YYViewController.m
 3 //  09-核心动画旋转
 4 //
 5 //  Created by apple on 14-6-21.
 6 //  Copyright (c) 2014年 itcase. All rights reserved.
 7 //
 8 
 9 #import "YYViewController.h"
10 
11 @interface YYViewController ()
12 @property(nonatomic,strong)CALayer *myLayer;
13 @end
14 
15 @implementation YYViewController
16 - (void)viewDidLoad
17 {
18     [super viewDidLoad];
19     
20     //创建layer
21     CALayer *myLayer=[CALayer layer];
22     //设置layer的属性
23     myLayer.bounds=CGRectMake(0, 0, 150, 60);
24     myLayer.backgroundColor=[UIColor yellowColor].CGColor;
25     myLayer.position=CGPointMake(50, 50);
26     myLayer.anchorPoint=CGPointMake(0, 0);
27     myLayer.cornerRadius=40;
28     //添加layer
29     [self.view.layer addSublayer:myLayer];
30     self.myLayer=myLayer;
31 }
32 
33 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
34 {
35     //1.创建动画
36     CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:@"transform"];
37     //1.1设置动画执行时间
38     anima.duration=2.0;
39     //1.2修改属性,执行动画
40     anima.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2+M_PI_4, 1, 1, 0)];
41     //1.3设置动画执行完毕后不删除动画
42     anima.removedOnCompletion=NO;
43     //1.4设置保存动画的最新状态
44     anima.fillMode=kCAFillModeForwards;
45     
46     //2.添加动画到layer
47     [self.myLayer addAnimation:anima forKey:nil];
48 }
49 @end
复制代码
实现效果:
   


提示:如果要让图形以2D的方式旋转,只需要把CATransform3DMakeRotation在z方向上的值改为1即可。


anima.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2+M_PI_4, 1, 1, 0)];


四、补充


可以通过transform(KVC)的方式来进行设置。


代码示例(平移):


复制代码
 1 #import "YYViewController.h"
 2 
 3 @interface YYViewController ()
 4 @property(nonatomic,strong)CALayer *myLayer;
 5 @end
 6 
 7 @implementation YYViewController
 8 - (void)viewDidLoad
 9 {
10     [super viewDidLoad];
11     
12     //创建layer
13     CALayer *myLayer=[CALayer layer];
14     //设置layer的属性
15     myLayer.bounds=CGRectMake(0, 0, 150, 60);
16     myLayer.backgroundColor=[UIColor yellowColor].CGColor;
17     myLayer.position=CGPointMake(50, 50);
18     myLayer.anchorPoint=CGPointMake(0, 0);
19     myLayer.cornerRadius=40;
20     //添加layer
21     [self.view.layer addSublayer:myLayer];
22     self.myLayer=myLayer;
23 }
24 
25 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
26 {
27     //1.创建动画
28     CABasicAnimation *anima=[CABasicAnimation animation];
29     anima.keyPath=@"transform";
30     //1.1设置动画执行时间
31     anima.duration=2.0;
32     //1.2修改属性,执行动画
33   
34     anima.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, 100, 1)];
35     //1.3设置动画执行完毕后不删除动画
36     anima.removedOnCompletion=NO;
37     //1.4设置保存动画的最新状态
38     anima.fillMode=kCAFillModeForwards;
39     
40     //2.添加动画到layer
41     [self.myLayer addAnimation:anima forKey:nil];
42 }
复制代码
实现效果:


绘制的图形在y的方向上移动100个单位。
========

iOS开发UI篇—核心动画简介

http://www.cnblogs.com/wendingding/p/3801036.html


一、简单介绍


Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍。也就是说,使用少量的代码就可以实现非常强大的功能。


Core Animation是跨平台的,可以用在Mac OS X和iOS平台。


Core Animation的动画执行过程都是在后台操作的,不会阻塞主线程。不阻塞主线程,可以理解为在执行动画的时候还能点击(按钮)。


要注意的是,Core Animation是直接作用在CALayer上的,并非UIView。
 
二、Core Animation的使用步骤


1.使用它需要先添加QuartzCore.framework框架和引入主头文件<QuartzCore/QuartzCore.h>(iOS7不需要)


2.初始化一个CAAnimation对象,并设置一些动画相关属性


3.通过调用CALayer的addAnimation:forKey:方法增加CAAnimation对象到CALayer中,这样就能开始执行动画了


4.通过调用CALayer的removeAnimationForKey:方法可以停止CALayer中的动画




三、CAAnimation


类的继承结构图
 


CAAnimation是所有动画类的父类,但是它不能直接使用,应该使用它的子类。


 常见属性有:


duration:动画的持续时间


repeatCount:动画的重复次数


timingFunction:控制动画运行的节奏


说明:(1)能用的动画类只有4个子类:CABasicAnimation、CAKeyframeAnimation、CATransition、CAAnimationGroup


     (2)CAMediaTiming是一个协议(protocol)。


CAPropertyAnimation是CAAnimation的子类,但是不能直接使用,要想创建动画对象,应该使用它的两个子类:CABasicAnimation和CAKeyframeAnimation


它有个NSString类型的keyPath属性,你可以指定CALayer的某个属性名为keyPath,并且对CALayer的这个属性的值进行修改,达到相应的动画效果。比如,指定@"position"为keyPath,就会修改CALayer的position属性的值,以达到平移的动画效果




四、补充说明


所有动画对象的父类,负责控制动画的持续时间和速度,是个抽象类,不能直接使用,应该使用它具体的子类


属性解析:(红色代表来自CAMediaTiming协议的属性)


duration:动画的持续时间


repeatCount:动画的重复次数


repeatDuration:动画的重复时间


removedOnCompletion:默认为YES,代表动画执行完毕后就从图层上移除,图形会恢复到动画执行前的状态。如果想让图层保持显示动画执行后的状态,那就设置为NO,不过还要设置fillMode为kCAFillModeForwards


fillMode:决定当前对象在非active时间段的行为.比如动画开始之前,动画结束之后


beginTime:可以用来设置动画延迟执行时间,若想延迟2s,就设置为CACurrentMediaTime()+2,CACurrentMediaTime()为图层的当前时间


timingFunction:速度控制函数,控制动画运行的节奏


delegate:动画代理
========
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值