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

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

   一种是UIView层面的,curl

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

 

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

 

 [UIView beginAnimations:@"Curl"context:nil];//动画开始 
 [UIView setAnimationDuration:0.75]; 
 [UIView setAnimationDelegate:self];
 [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES]; 
[myview removeFromSuperview]; 
[UIView commitAnimations];
 

 

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

基本使用方法能够看一下以下例子:orm

 

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里定义的,他们的参数说明能够参考以下:ip

 

[animation setType:@"suckEffect"];ci

这里的suckEffect就是效果名称,能够用的效果主要有:rem

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

最后再给出一种经常使用代码供你们参考。animation

// Curl the image up or down
 
 CATransition *animation = [CATransition animation];
 [animation setDuration:0.35];
 [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
 
 if (!curled)
   { 
       //animation.type = @"mapCurl"; 
         animation.type = @"pageCurl";
         animation.fillMode = kCAFillModeForwards; 
         animation.endProgress = 0.99;
    } else { 
      //animation.type = @"mapUnCurl";
        animation.type = @"pageUnCurl";
        animation.fillMode = kCAFillModeBackwards; animation.startProgress = 0.01; 
 } 
 
[animation setRemovedOnCompletion:NO];
[view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; 
[view addAnimation:animation forKey"pageCurlAnimation"]; 
// Disable user interaction where necessary 
 
if (!curled) { 
 
 else { 
 
 } 
 
curled = !curled;
相关文章
相关标签/搜索