ios 动画效果类型及实现方法

实现iphone动画效果主要有两种方法,一种是UIView层面的,一种是使用CATransition进行更低层次的控制.

1、UIView

CGContextRef context = UIGraphicsGetCurrentContext(); 
[UIView beginAnimations:nil context:context]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDuration:1.0];          //动画持续的时间 
 
//这里添加你对UIView所做改变的代码 
 
//[UIView setAnimationDidStopSelector:@selector(animationFinished:)];   //动画停止后,执行某个方法 
[UIView commitAnimations]; 


2、UIView(使用CocoaTouch)

CGContextRef context = UIGraphicsGetCurrentContext(); 
[UIView beginAnimations:nil context:context]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:1.0]; 
 
// Cocoa Touch   
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:myView cache:YES]; 
 
[UIView setAnimationDelegate:self]; 
//[UIView setAnimationDidStopSelector:@selector(animationFinished:)]; //动画停止后,执行某个方法 
[UIView commitAnimations]; 
动画方式(UIViewAnimationTransition): 
    UIViewAnimationTransitionFlipFromLeft              //从左向右翻转 
    UIViewAnimationTransitionFlipFromRight             //从右向左翻转 
    UIViewAnimationTransitionCurlUp                    //从下向上翻页 
    UIViewAnimationTransitionCurlDown                  //从上向下翻页 


3、CATransition

头部导入 #import<QuartzCore/QuartzCore.h>

CATransition *animation = [CATransition animation]; 
     animation.delegate = self; 
     animation.duration = 1.0f;       //动画执行时间 
     animation.timingFunction = UIViewAnimationCurveEaseInOut; 
     animation.type = kCATransitionFade; 
     animation.subtype = kCATransitionFromRight; 
     
// 这里添加你对UIView所做改变的代码 
 
[[myView layer] addAnimation:animation forKey:@"animation"]; 


setType:有四种类型:

kCATransitionFade                   //交叉淡化过渡                    
kCATransitionMoveIn               //移动覆盖原图                    
kCATransitionPush                    //新视图将旧视图推出去                    
kCATransitionReveal                //底部显出来     


setSubtype:有四种类型:

kCATransitionFromRight;                    
kCATransitionFromLeft(默认值)                    
kCATransitionFromTop;                    
kCATransitionFromBottom         
注:kCATransitionFade 不支持Subtype      


4、CATransition(只使用setType,参数是NSString)    

CATransition *animation = [CATransition animation];     
 animation.delegate = self;      
 animation.duration = 1.0f;   //动画执行时间      
 animation.timingFunction = UIViewAnimationCurveEaseInOut;      
 animation.type = @"suckEffect";// 这里添加你对UIView所做改变的代码      
 [[myView layer] addAnimation:animation forKey:@"animation"];     


可以用的效果主要有:

pageCurl     //向上翻一页      
pageUnCurl   //向下翻一页       
rippleEffect   //滴水效果       
suckEffect     //收缩效果,如一块布被抽走    
cube       //立方体效果     
oglFlip      //上下翻转效果 



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值