iphone的动画效果类型及实现方法

实现iphone漂亮的动画效果主要有两种方法,

   一种是UIView层面的,

  一种是使用CATransition进行更低层次的控制,

 

      第一种是UIView,UIView方式可能在低层也是使用CATransition进行了封装,它只能用于一些简单的、常用的效果展现,这里写一个常用的示例代码,供大家参考。

 

Cpp代码
  1.  [UIView beginAnimations:@"Curl" context:nil];//动画开始    
  2.  [UIView setAnimationDuration:0.75];   
  3.  [UIView setAnimationDelegate:self];  
  4.  [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES];   
  5. [myview removeFromSuperview];   
  6. [UIView commitAnimations];  
 [UIView beginAnimations:@"Curl"context:nil];//动画开始 
 [UIView setAnimationDuration:0.75]; 
 [UIView setAnimationDelegate:self];
 [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES]; 
[myview removeFromSuperview]; 
[UIView commitAnimations];

 

 

       第二种方式相对复杂一些,但如果更好的进行控制,还是使用这种方法吧,

基本使用方法可以看一下如下例子:

 

Cpp代码
  1. CATransition *animation  = [CATransition animation ];  
  2. [animation  setDuration:1.25f];   
  3. [animation  setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];   
  4. [animation  setType :kCATransitionReveal];  
  5. [animation  setSubtype: kCATransitionFromBottom];  
  6. [self.view.layer addAnimation:animation  forKey:@"Reveal" ];  
CATransition *animation
 = [CATransition animation
];
[animation
 setDuration:1.25f]; 
[animation
 setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; 
[animation
 setType
:kCATransitionReveal];
[animation
 setSubtype: kCATransitionFromBottom];
[self.view.layer addAnimation:animation
 forKey:@"Reveal"];

 

这里使用了setType 与setSubtype组合,这使用个比较保险,因为他的参数就是官方API里定义的,他们的参数说明可以参考如下:

 

[animation setType :@"suckEffect"];

这里的suckEffect就是效果名称,可以用的效果主要有:

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

 pageUnCurl 向下翻一页 

 rippleEffect 滴水效果 

 suckEffect 收缩效果,如一块布被抽走 

 cube 立方体效果 

 oglFlip 上下翻转效果 

 

最后再给出一种常用代码供大家参考。

Cpp代码
  1. // Curl the image up or down   
  2.   
  3.  CATransition *animation  = [CATransition animation ];  
  4.  [animation  setDuration:0.35];  
  5.  [animation  setTimingFunction:UIViewAnimationCurveEaseInOut];  
  6.   
  7.  if  (!curled)  
  8.    {   
  9.        //animation .type = @"mapCurl";    
  10.          animation .type = @"pageCurl" ;  
  11.          animation .fillMode = kCAFillModeForwards;   
  12.          animation .endProgress = 0.99;  
  13.     } else  {   
  14.       //animation .type = @"mapUnCurl";   
  15.         animation .type = @"pageUnCurl" ;  
  16.         animation .fillMode = kCAFillModeBackwards; animation .startProgress = 0.01;   
  17.  }   
  18.   
  19. [animation  setRemovedOnCompletion:NO];  
  20. [view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];   
  21. [view addAnimation:animation  forKey"pageCurlAnimation" ];   
  22. // Disable user interaction where necessary    
  23.   
  24. if  (!curled) {   
  25. }   
  26.   
  27.  else  {   
  28.   
  29.  }   
  30.   
  31. curled = !curled;  
  32. code:http://dl.javaeye.com/topics/download/339b059a-1b78-398c-9763-0569744ad7e0

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值