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 效果展现

相关文章
相关标签/搜索