UINavigationController 自定義轉(zhuǎn)場動(dòng)畫(模仿淘寶App跳轉(zhuǎn))

Show效果展示

Modal 效果展示

制作目的

  • 想要自定義系統(tǒng)轉(zhuǎn)場動(dòng)畫速度
  • 放棄不順暢的 NavigationBar 隱藏消失
  • 干脆直接干掉每個(gè)頁面的 NavigationBar,在使用 UINavigationController 管理的同時(shí),每個(gè)頁面的 NavigationBar 都使用自定義的 UIView, 這樣既定制程度高又可以在不需要 NavigationBar 的頁面無縫對(duì)接,包括一些之前 NavigationBar 動(dòng)畫也可以更輕松的利用自定義的 UIView 的適配動(dòng)畫來更靈活的實(shí)現(xiàn)

實(shí)現(xiàn)功能

  • 可以設(shè)置一個(gè)自己認(rèn)為舒服的速度進(jìn)行轉(zhuǎn)場動(dòng)畫(該動(dòng)畫模仿系統(tǒng)轉(zhuǎn)場動(dòng)畫效果,如果需要其他轉(zhuǎn)場動(dòng)畫可以替換我的 LGFTransition 類,或者修改 LGFTransition 類的代碼)
  • 這個(gè)動(dòng)畫速度同時(shí)也舒服的作用到邊緣手勢(shì)拖動(dòng) POP 返回上

使用方式

  • pod 'LGFTransition' 或者 LGFTransition

  • 接著在 AppDelegate 中導(dǎo)入頭文件 UINavigationController+LGFAnimatedTransition.h

#import "UINavigationController+LGFAnimatedTransition.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Configure whether to use a custom transition animation here
    [UINavigationController lgf_AnimatedTransitionIsUse:YES];
//    [UINavigationController lgf_AnimatedTransitionIsUse:YES showDuration: 1.0 modalDuration:1.0];
    return YES;
}
  • 在 didFinishLaunchingWithOptions 方法中調(diào)用 UINavigationController 由分類添加的新方法 lgf_AnimatedTransitionIsUse
  • 傳 NO 或不掉用該方法 使用系統(tǒng)效果, 調(diào)用該方法并傳 YES 啟用本效果
  • showDuration Show動(dòng)畫想要執(zhí)行的時(shí)間,默認(rèn) 0.5 秒
  • modalDuration Modal動(dòng)畫想要執(zhí)行的時(shí)間,默認(rèn) 0.5 秒

Demo 里還添加了一個(gè)可以讓普通按鈕變成pop返回按鈕的 UIButton 父類

  • 自定義 NavigationBar 上的 UIButton 直接繼承 LGFNavigationBackButton 就可以有pop返回的功能了
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。