1. 程式人生 > >UINavigationController 自定義轉場動畫(模仿淘寶App跳轉)

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

imp dal iap 默認 自定義轉場動畫 ict oda ack 調用

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

實現功能

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

使用方式

  • pod ‘LGFAnimatedNavigation‘ 或者 LGFAnimatedNavigation

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

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

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

Show 效果展示

技術分享圖片

Modal 效果展示

技術分享圖片

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