UINavigationController 自定義轉場動畫(模仿淘寶App跳轉)

製做目的

  • 想要自定義系統轉場動畫速度
  • 放棄不暢的 NavigationBar 隱藏消失
  • 乾脆直接幹掉每一個頁面的 NavigationBar,在使用 UINavigationController 管理的同時,每一個頁面的 NavigationBar 都使用自定義的 UIView, 這樣既定製程度高又能夠在不須要 NavigationBar 的頁面無縫對接,包括一些以前 NavigationBar 動畫也能夠更輕鬆的利用自定義的 UIView 的適配動畫來更靈活的實現

實現功能

  • 能夠設置一個本身認爲舒服的速度進行轉場動畫(該動畫模仿系統轉場動畫效果,若是須要其餘轉場動畫能夠替換個人 LGFTransition 類,或者修改 LGFTransition 類的代碼)
  • 這個動畫速度同時也舒服的做用到邊緣手勢拖動 POP 返回上

使用方式

  • pod 'LGFTransition' 或者 LGFTransitiongit

  • 接着在 AppDelegate 中導入頭文件 UINavigationController+LGFAnimatedTransition.hgithub

#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 方法中調用 UINavigationController 由分類添加的新方法 lgf_AnimatedTransitionIsUse
  • 傳 NO 或不掉用該方法 使用系統效果, 調用該方法並傳 YES 啓用本效果
  • showDuration Show動畫想要執行的時間,默認 0.5 秒
  • modalDuration Modal動畫想要執行的時間,默認 0.5 秒

Demo 裏還添加了一個能夠讓普通按鈕變成pop返回按鈕的 UIButton 父類

  • 自定義 NavigationBar 上的 UIButton 直接繼承 LGFNavigationBackButton 就能夠有pop返回的功能了

Show 效果展現

Show 效果展現

Modal 效果展現

Modal 效果展現

相關文章
相關標籤/搜索