iOS开发动画(Animation)总结

动画浅析-CAAnimation和CATransition


现在明白了,要做动画。需要用到CATransition类!
那就学习一下吧!
 先贴一个入门代码!

[_imgPic setImage:image];// 设置新的图片

            

           

            CATransition *animation = [CATransition animation];

            [animation setDuration:1.0];

            [animation setFillMode:kCAFillModeForwards];

            [animation setTimingFunction:[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut]];

            [animation setType:@"rippleEffect"];// rippleEffect

            [animation setSubtype:kCATransitionFromTop];

            [_imgPic.layer addAnimation:animation forKey:nil];


实现功能就是,在UIImageView换新图片的时候,做相应的动画效果!好让,UIImageView转化时,不至于太单调!

第一句,就让我很困惑!
CATransition *animation = [CATransition animation];
(id)animation方法
创建一个CATransition对象。但是CATransition并没有animation方法?!

@interface CATransition : CAAnimation


原来如此,CATransitionCAAnimation的子类

骑驴看唱本吧!

CAAnimation

CAAnimation类,是一个抽象类。遵循CAMediaTiming协议和CAAction协议!

CAAnimation is an abstract animation class. It provides the basic support for the CAMediaTiming and CAActionprotocols.

CAMediaTiming协议

可以调整时间,包括持续时间,速度,重复次数。

CAAction协议

可以通过响应动作的方式来显示动画。


CAAnimation有很多派生类

 

CATransition 提供渐变效果:(推拉push效果,消退fade效果,揭开reveal效果)。

 

CAAnimationGroup 允许多个动画同时播放。

 

CABasicAnimation 提供了对单一动画的实现。

 

CAKeyframeAnimation 关键桢动画,可以定义行动路线。

 

CAConstraint 约束类,在布局管理器类中用它来设置属性。

 

CAConstraintLayoutManager 约束布局管理器,是用来将多个CALayer进行布局的.各个CALayer是通过名称来区分,而布局属性是通过CAConstraint来设置的。

 

CATransaction 事务类,可以对多个layer的属性同时进行修改.它分隐式事务,和显式事务。

 CAAnimation属性

delegate

@property(retain) id delegate
为CAAnimation设置代理。默认为nil。
注意:一个CAAnimation实例,不能设置delegate为self。会引起循环引用。

removedOnCompletion

@property(getter=isRemovedOnCompletion) BOOL removedOnCompletion
设置是否动画完成后,动画效果从设置的layer上移除。默认为YES。

timingFunction
@property(retain) CAMediaTimingFunction *timingFunction
设置动画的“时机”效果。就是动画自身的“节奏”:比如:开始快,结束时变慢;开始慢,结束时变快;匀速;等,在动画过程中的“时机”效果。

animation
(id)animation
创建并返回一个CAAnimation实例。

defaultValueForKey

(id)defaultValueForKey:(NSString *)key
根据属性key,返回相应的属性值。

CAAnimation实例方法

shouldArchiveValueForKey

(BOOL)shouldArchiveValueForKey:(NSString *)key
返回指定的属性值是否可以归档。
key:指定的属性。
YES:指明该属性可以被归档;NO:不能被归档。

CAAnimation协议方法

animationDidStart

(void)animationDidStart:(CAAnimation *)theAnimation
动画开始时,执行的方法。
theAnimation:正在执行动画的CAAnimation实例。

animationDidStop:finished

(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
动画执行完成或者动画为执行被删除时,执行该方法。
theAnimation:完成或者被删除的动画实例
flag:标志该动画是执行完成或者被删除:YES:执行完成;NO:被删除。

只是生硬的翻译了一下CAAnimation类。毕竟该类是其他动画的父类。


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];//关闭动画  






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值