天天看點

【iOS開發】---- 轉場動畫 CATransition

Inherits from CAAnimation :  NSObject
Conforms to

NSCoding (CAAnimation)

NSCopying (CAAnimation)

CAAction (CAAnimation)

CAMediaTiming (CAAnimation)

NSObject (NSObject)

Framework /System/Library/Frameworks/ QuartzCore.framework
Availability Available in iOS 2.0 and later.
Declared in CAAnimation.h

       CATransition類實作層的轉場動畫。你可以從一組預定義的轉換或者通過提供定制的CIFilter執行個體來指定轉場效果。

//定義個轉場動畫
    CATransition *animation = [CATransition animation];
    //轉場動畫持續時間
    animation.duration = 0.2f;
    //計時函數,從頭到尾的流暢度???
    animation.timingFunction=UIViewAnimationCurveEaseInOut;
    //轉場動畫類型
    animation.type = kCATransitionReveal;
    //轉場動畫将去的方向
    animation.subtype = kCATransitionFromBottom;
    //動畫時你需要的實作
    self.tabBarController.tabBar.hidden = YES;
      //添加動畫 (轉場動畫是添加在層上的動畫)
  	[self.tabBarController.tabBar.layer addAnimation:animation forKey:@"animation"];
           

說明:

duration:動畫持續的時長。

timingFunction:沒明白(誰明白的說明一下吧)

type:轉場動畫的類型。如果在一個自定義的轉場動畫中指定的過濾器屬性,此屬性将被忽略。

type共有四種類型:

NSString * const kCATransitionFade;//逐漸消失
NSString * const kCATransitionMoveIn;//移入
NSString * const kCATransitionPush;//平移(暫且這麼稱呼吧)
NSString * const kCATransitionReveal;//顯露      

預設類型為kCATransitionFade。

subtype:轉場動畫将要去往的方向。

subtpye有四種類型:

NSString * const kCATransitionFromRight;
NSString * const kCATransitionFromLeft;
NSString * const kCATransitionFromTop;
NSString * const kCATransitionFromBottom;      

預設方向是nil。

[self.tabBarController.tabBar.layer addAnimation:animation forKey:@"animation"];

轉場動畫是添加給layer的!

以下幾種轉場動畫調用的蘋果的私有API,注意咯,小心用了之後被蘋果打回來。

switch (btn.tag) {
case 0:
animation.type = @"cube";//---立方體
break;
case 1:
animation.type = @"suckEffect";//103 吸走的效果
break;
case 2://前後翻轉效果
animation.type = @"oglFlip";//When subType is "fromLeft" or "fromRight", it's the official one.
break;
case 3:
animation.type = @"rippleEffect";//110波紋效果
break;
case 4:
animation.type = @"pageCurl";//101翻頁起來
break;
case 5:
animation.type = @"pageUnCurl";//102翻頁下來
break;
case 6:
animation.type = @"cameraIrisHollowOpen ";//107//鏡頭開
break;
case 7:
animation.type = @"cameraIrisHollowClose ";//106鏡頭關
break;
default:
break;
}