本文主要是記錄一些在網(wǎng)上找到的一些方法,然后自己整理了下讓自己更好理解一點(diǎn)舵稠, 如有侵權(quán)超升,請(qǐng)告知
本次實(shí)現(xiàn)的代碼主要是在網(wǎng)上下載的一些轉(zhuǎn)場(chǎng)動(dòng)畫(huà)的基礎(chǔ)上更改一下
但是源代碼下載地址給忘了,有點(diǎn)對(duì)不起原作者了柱查,所以才想著平時(shí)記錄一些代碼廓俭,不然過(guò)段時(shí)間就又會(huì)忘記,
下面會(huì)把我寫(xiě)的一個(gè)小demo貼上來(lái) 望指教...
剛剛找源代碼地址沒(méi)找到唉工,找到了幾篇文章
http://blog.csdn.net/ityanping/article/details/39270609
該文章內(nèi)容為:
視圖切換研乒,沒(méi)有NavigationController的情況下,一般會(huì)使用presentViewController來(lái)切換視圖并攜帶切換時(shí)的動(dòng)畫(huà)淋硝,
其中切換方法如下:
– presentViewController:animated:completion: 彈出雹熬,出現(xiàn)一個(gè)新視圖 可以帶動(dòng)畫(huà)效果宽菜,完成后可以做相應(yīng)的執(zhí)行函數(shù)經(jīng)常為nil
– dismissViewControllerAnimated:completion:退出一個(gè)新視圖 可以帶動(dòng)畫(huà)效果,完成后可以做相應(yīng)的執(zhí)行函數(shù)經(jīng)常為nil
切換動(dòng)畫(huà)在壓入一個(gè)新視圖和彈出頂層視圖均可以使用竿报,下面只以壓入視圖為例铅乡。
presentModalViewController:animated:completion:使用系統(tǒng)自帶四種動(dòng)畫(huà)
簡(jiǎn)單的實(shí)現(xiàn)方式:
[page2Controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:myNextViewController animated:YES? completion:nil];
系統(tǒng)支持的四種動(dòng)畫(huà):
typedef enum {
UIModalTransitionStyleCoverVertical=0, //默認(rèn)方式,豎向上推
UIModalTransitionStyleFlipHorizontal, //水平反轉(zhuǎn)
UIModalTransitionStyleCrossDissolve,//隱出隱現(xiàn)
UIModalTransitionStylePartialCurl,//部分翻頁(yè)效果
} UIModalTransitionStyle;
presentModalViewController:animated:completion: 不用自帶的四種動(dòng)畫(huà)效果
實(shí)現(xiàn)全翻頁(yè)效果:
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];
常見(jiàn)的轉(zhuǎn)換類(lèi)型(type):
kCATransitionFade? ? ? ? ? ? ? //淡出
kCATransitionMoveIn? ? ? ? ? //覆蓋原圖
kCATransitionPush? ? ? ? ? ? ? //推出
kCATransitionReveal? ? ? ? ? //底部顯出來(lái)
SubType:
kCATransitionFromRight
kCATransitionFromLeft? ? // 默認(rèn)值
kCATransitionFromTop
kCATransitionFromBottom
設(shè)置其他動(dòng)畫(huà)類(lèi)型的方法(type):
pageCurl? 向上翻一頁(yè)
pageUnCurl 向下翻一頁(yè)
rippleEffect 滴水效果
suckEffect 收縮效果烈菌,如一塊布被抽走
cube 立方體效果
oglFlip 上下翻轉(zhuǎn)效果阵幸;
自己實(shí)現(xiàn):
代碼地址:http://download.csdn.net/my
首先自定義一個(gè)類(lèi)來(lái)管理轉(zhuǎn)場(chǎng)效果
主要代碼有
.h文件
聲明一個(gè)枚舉來(lái)定義轉(zhuǎn)場(chǎng)類(lèi)型
typedef enum : NSUInteger {
/**
*? 淡入淡出
*/
AnimationTypeFade = 1,
/**
*? 推擠
*/
AnimationTypePush,
/**
*? 揭開(kāi)
*/
AnimationTypeReveal,
/**
*? 覆蓋
*/
AnimationTypeMoveIn,
/**
*? 立方體
*/
AnimationTypeCube,
/**
*? 吮吸
*/
AnimationTypeSuckEffect,
/**
*? 翻轉(zhuǎn)
*/
AnimationTypeOglFlip,
/**
*? 波紋
*/
AnimationTypeRippleEffect,
/**
*? 翻頁(yè)
*/
AnimationTypePageCurl,
/**
*? 反翻頁(yè)
*/
AnimationTypePageUnCurl,
/**
*? 開(kāi)鏡頭
*/
AnimationTypeCameraIrisHollowOpen,
/**
*? 關(guān)鏡頭
*/
AnimationTypeCameraIrisHollowClose,
/**
*? 下翻頁(yè)
*/
AnimationTypeCurlDown,
/**
*? 上翻頁(yè)
*/
AnimationTypeCurlUp,
/**
*? 左翻轉(zhuǎn)
*/
AnimationTypeFlipFromLeft,
/**
*? 右翻轉(zhuǎn)
*/
AnimationTypeFlipFromRight,
} AnimationType;
再聲明一個(gè)枚舉來(lái)管理轉(zhuǎn)場(chǎng)方向
/**
定義轉(zhuǎn)場(chǎng)方向
*/
typedef enum : NSUInteger {
AnimationDirectionBottom = 0,
AnimationDirectionLeft,
AnimationDirectionRight,
AnimationDirectionTop
} AnimationDirection;
聲明一個(gè)方法
/**
*? 自定義轉(zhuǎn)場(chǎng)效果
*
*? @param type? ? ? ? ? ? ? 轉(zhuǎn)場(chǎng)類(lèi)型 push 或者 其他類(lèi)型
*? @param animationDirection 轉(zhuǎn)場(chǎng)方向
*? @param duration? ? ? ? ? 時(shí)間 默認(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文件實(shí)現(xiàn)方法
+ (void)transitionWithType:(AnimationType)type WithAnimationDirection:(AnimationDirection)animationDirection duration:(NSTimeInterval)duration fromVC:(UIViewController *)fromViewController toVC:(UIViewController *)toViewController
{
//創(chuàng)建CATransition對(duì)象
CATransition *animation = [CATransition animation];
NSString *animationType = kCATransitionFade;
//設(shè)置運(yùn)動(dòng)時(shí)間
animation.duration = duration ? duration : 1.f;
switch (type) {
case AnimationTypeFade://淡入淡出
{
animationType =kCATransitionFade;
}
break;
case AnimationTypePush://推擠
{
animationType =kCATransitionPush;
}
break;
case AnimationTypeReveal://揭開(kāi)
{
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://翻頁(yè)
{
animationType =@"pageCurl";
}
break;
case AnimationTypePageUnCurl://反翻頁(yè)
{
animationType =@"pageUnCurl";
}
break;
case AnimationTypeCameraIrisHollowOpen://開(kāi)鏡頭
{
animationType =@"cameraIrisHollowOpen";
}
break;
case AnimationTypeCameraIrisHollowClose://關(guān)鏡頭
{
animationType =@"cameraIrisHollowClose";
}
break;
case AnimationTypeCurlDown://下翻頁(yè)
{
animationType =@"pageUnCurl";
}
break;
case AnimationTypeCurlUp://上翻頁(yè)
{
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)動(dòng)type
animation.type = animationType;
if (subtype != nil) {
//設(shè)置子類(lèi)
animation.subtype = subtype;
}
//設(shè)置運(yùn)動(dòng)速度
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[fromViewController.view.window.layer addAnimation:animation forKey:@"animation"];
[fromViewController presentViewController:toViewController animated:NO completion:nil];
}
demo下載地址:https://github.com/lwy121810/WYAnimationTool