ios学习--详解IPhone动画效果类型及实现方法

来源:互联网 发布:同声翻译软件手机版 编辑:程序博客网 时间:2024/06/02 00:15

详解IPhone动画效果类型及实现方法是本文要介绍的内容,主要介绍了iphone动画的实现方法,不多说,我们一起来看内容。

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

1、UIView

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

2、UIView(使用Cocoa Touch)

  1. CGContextRef context = UIGraphicsGetCurrentContext();  
  2. [UIView beginAnimations:nil context:context];  
  3. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  4. [UIView setAnimationDuration:1.0];  
  5.  
  6. // Cocoa Touch    
  7. [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:myView cache:YES];  
  8.  
  9. [UIView setAnimationDelegate:self];  
  10. //[UIView setAnimationDidStopSelector:@selector(animationFinished:)]; //动画停止后,执行某个方法  
  11. [UIView commitAnimations];  
  12. 动画方式(UIViewAnimationTransition):  
  13.     UIViewAnimationTransitionFlipFromLeft              //从左向右翻转  
  14.     UIViewAnimationTransitionFlipFromRight             //从右向左翻转  
  15.     UIViewAnimationTransitionCurlUp                    //从下向上翻页  
  16.     UIViewAnimationTransitionCurlDown                  //从上向下翻页 

3、CATransition

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

setType:有四种类型:

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

setSubtype:有四种类型:

  1. kCATransitionFromRight;                     
  2. kCATransitionFromLeft(默认值)                     
  3. kCATransitionFromTop;                     
  4. kCATransitionFromBottom          
  5. 注:kCATransitionFade 不支持Subtype      

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

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

可以用的效果主要有:

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

小结:详解IPhone动画效果类型及实现方法的内容介绍完了,希望本文对你有所帮助

原创粉丝点击