自定義專場動畫 presentViewController實現(xiàn)從左到右等多個方向

本文主要是記錄一些在網(wǎng)上找到的一些方法,然后自己整理了下讓自己更好理解一點, 如有侵權(quán),請告知

本次實現(xiàn)的代碼主要是在網(wǎng)上下載的一些轉(zhuǎn)場動畫的基礎(chǔ)上更改一下

但是源代碼下載地址給忘了,有點對不起原作者了,所以才想著平時記錄一些代碼,不然過段時間就又會忘記,

剛剛找源代碼地址沒找到,找到了幾篇文章

http://blog.csdn.net/ityanping/article/details/39270609

該文章內(nèi)容為:

視圖切換,沒有NavigationController的情況下,一般會使用presentViewController來切換視圖并攜帶切換時的動畫,

其中切換方法如下:

– presentViewController:animated:completion: 彈出,出現(xiàn)一個新視圖 可以帶動畫效果,完成后可以做相應(yīng)的執(zhí)行函數(shù)經(jīng)常為nil

– dismissViewControllerAnimated:completion:退出一個新視圖 可以帶動畫效果,完成后可以做相應(yīng)的執(zhí)行函數(shù)經(jīng)常為nil

切換動畫在壓入一個新視圖和彈出頂層視圖均可以使用,下面只以壓入視圖為例。

presentModalViewController:animated:completion:使用系統(tǒng)自帶四種動畫

簡單的實現(xiàn)方式:

[page2Controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

[self presentModalViewController:myNextViewController animated:YES? completion:nil];

系統(tǒng)支持的四種動畫:

typedef enum {

UIModalTransitionStyleCoverVertical=0, //默認(rèn)方式,豎向上推

UIModalTransitionStyleFlipHorizontal, //水平反轉(zhuǎn)

UIModalTransitionStyleCrossDissolve,//隱出隱現(xiàn)

UIModalTransitionStylePartialCurl,//部分翻頁效果

} UIModalTransitionStyle;

presentModalViewController:animated:completion: 不用自帶的四種動畫效果

實現(xiàn)全翻頁效果:

CATransition *animation = [CATransition animation];

animation.duration = 1.0;

animation.timingFunction = UIViewAnimationCurveEaseInOut;

animation.type = @"pageCurl";

//animation.type = kCATransitionPush;

animation.subtype = kCATransitionFromLeft;

[self.view.window.layer addAnimation:animation forKey:nil];

[self presentModalViewController:myNextViewController animated:NO completion:nil];

常見的轉(zhuǎn)換類型(type):

kCATransitionFade? ? ? ? ? ? ? //淡出

kCATransitionMoveIn? ? ? ? ? //覆蓋原圖

kCATransitionPush? ? ? ? ? ? ? //推出

kCATransitionReveal? ? ? ? ? //底部顯出來

SubType:

kCATransitionFromRight

kCATransitionFromLeft? ? // 默認(rèn)值

kCATransitionFromTop

kCATransitionFromBottom

設(shè)置其他動畫類型的方法(type):

pageCurl? 向上翻一頁

pageUnCurl 向下翻一頁

rippleEffect 滴水效果

suckEffect 收縮效果,如一塊布被抽走

cube 立方體效果

oglFlip 上下翻轉(zhuǎn)效果;


自己實現(xiàn):


代碼地址:http://download.csdn.net/my

首先自定義一個類來管理轉(zhuǎn)場效果

主要代碼有

.h文件

聲明一個枚舉來定義轉(zhuǎn)場類型

typedef enum : NSUInteger {

/**

*? 淡入淡出

*/

AnimationTypeFade = 1,

/**

*? 推擠

*/

AnimationTypePush,

/**

*? 揭開

*/

AnimationTypeReveal,

/**

*? 覆蓋

*/

AnimationTypeMoveIn,

/**

*? 立方體

*/

AnimationTypeCube,

/**

*? 吮吸

*/

AnimationTypeSuckEffect,

/**

*? 翻轉(zhuǎn)

*/

AnimationTypeOglFlip,

/**

*? 波紋

*/

AnimationTypeRippleEffect,

/**

*? 翻頁

*/

AnimationTypePageCurl,

/**

*? 反翻頁

*/

AnimationTypePageUnCurl,

/**

*? 開鏡頭

*/

AnimationTypeCameraIrisHollowOpen,

/**

*? 關(guān)鏡頭

*/

AnimationTypeCameraIrisHollowClose,

/**

*? 下翻頁

*/

AnimationTypeCurlDown,

/**

*? 上翻頁

*/

AnimationTypeCurlUp,

/**

*? 左翻轉(zhuǎn)

*/

AnimationTypeFlipFromLeft,

/**

*? 右翻轉(zhuǎn)

*/

AnimationTypeFlipFromRight,

} AnimationType;


再聲明一個枚舉來管理轉(zhuǎn)場方向

/**

定義轉(zhuǎn)場方向

*/

typedef enum : NSUInteger {

AnimationDirectionBottom = 0,

AnimationDirectionLeft,

AnimationDirectionRight,

AnimationDirectionTop

} AnimationDirection;


聲明一個方法

/**

*? 自定義轉(zhuǎn)場效果

*

*? @param type? ? ? ? ? ? ? 轉(zhuǎn)場類型 push 或者 其他類型

*? @param animationDirection 轉(zhuǎn)場方向

*? @param duration? ? ? ? ? 時間 默認(rèn)為1s

*? @param fromViewController fromVC

*? @param toViewController? toVC

*/

+ (void)transitionWithType:(AnimationType)type WithAnimationDirection:(AnimationDirection)animationDirection duration:(NSTimeInterval)duration fromVC:(UIViewController *)fromViewController toVC:(UIViewController *)toViewController;



.m文件實現(xiàn)方法

+ (void)transitionWithType:(AnimationType)type WithAnimationDirection:(AnimationDirection)animationDirection duration:(NSTimeInterval)duration fromVC:(UIViewController *)fromViewController toVC:(UIViewController *)toViewController

{

//創(chuàng)建CATransition對象

CATransition *animation = [CATransition animation];

NSString *animationType = kCATransitionFade;

//設(shè)置運(yùn)動時間

animation.duration = duration ? duration : 1.f;

switch (type) {

case AnimationTypeFade://淡入淡出

{

animationType =kCATransitionFade;

}

break;

case AnimationTypePush://推擠

{

animationType =kCATransitionPush;

}

break;

case AnimationTypeReveal://揭開

{

animationType =kCATransitionReveal;

}

break;

case AnimationTypeMoveIn://覆蓋

{

animationType =kCATransitionMoveIn;

}

break;

case AnimationTypeCube://立方體

{

animationType =@"cube";

}

break;

case AnimationTypeSuckEffect://吮吸

{

animationType =@"suckEffect";

}

break;

case AnimationTypeOglFlip://翻轉(zhuǎn)

{

animationType =@"oglFlip";

}

break;

case AnimationTypeRippleEffect://波紋

{

animationType =@"rippleEffect";

}

break;

case AnimationTypePageCurl://翻頁

{

animationType =@"pageCurl";

}

break;

case AnimationTypePageUnCurl://反翻頁

{

animationType =@"pageUnCurl";

}

break;

case AnimationTypeCameraIrisHollowOpen://開鏡頭

{

animationType =@"cameraIrisHollowOpen";

}

break;

case AnimationTypeCameraIrisHollowClose://關(guān)鏡頭

{

animationType =@"cameraIrisHollowClose";

}

break;

case AnimationTypeCurlDown://下翻頁

{

animationType =@"pageUnCurl";

}

break;

case AnimationTypeCurlUp://上翻頁

{

animationType =@"pageUnCurl";

}

break;

case AnimationTypeFlipFromLeft://左翻轉(zhuǎn)

{

animationType =@"pageUnCurl";

}

break;

case AnimationTypeFlipFromRight://右翻轉(zhuǎn)

{

animationType =@"pageUnCurl";

}

break;

default:

break;

}

NSString *subtype = kCATransitionFromRight;

switch (animationDirection) {

case AnimationDirectionBottom:

{

subtype =kCATransitionFromBottom;

}

break;

case AnimationDirectionLeft:

{

subtype =kCATransitionFromLeft;

}

break;

case AnimationDirectionRight:

{

subtype =kCATransitionFromRight;

}

break;

case AnimationDirectionTop:

{

subtype =kCATransitionFromTop;

}

break;

default:

break;

}

//設(shè)置運(yùn)動type

animation.type = animationType;

if (subtype != nil) {

//設(shè)置子類

animation.subtype = subtype;

}

//設(shè)置運(yùn)動速度

animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;

[fromViewController.view.window.layer addAnimation:animation forKey:@"animation"];

[fromViewController presentViewController:toViewController animated:NO completion:nil];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 本文主要是記錄一些在網(wǎng)上找到的一些方法,然后自己整理了下讓自己更好理解一點, 如有侵權(quán),請告知 本次實現(xiàn)的代碼主要...
    哆啦_閱讀 706評論 0 0
  • 先看看CAAnimation動畫的繼承結(jié)構(gòu) CAAnimation{ CAPropertyAnimation { ...
    時間不會倒著走閱讀 1,799評論 0 1
  • 前言 本文只要描述了iOS中的Core Animation(核心動畫:隱式動畫、顯示動畫)、貝塞爾曲線、UIVie...
    GitHubPorter閱讀 3,741評論 7 11
  • 【iOS開發(fā)】30多個iOS常用動畫,帶詳細(xì)注釋 (2014-04-20 14:55:54)轉(zhuǎn)載▼標(biāo)簽: ios開...
    Fun箱Dao柜閱讀 1,683評論 0 50
  • 在iOS實際開發(fā)中常用的動畫無非是以下四種:UIView動畫,核心動畫,幀動畫,自定義轉(zhuǎn)場動畫。 1.UIView...
    請叫我周小帥閱讀 3,324評論 1 23

友情鏈接更多精彩內(nèi)容