温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

UINavigationController 自定义转场动画(模仿淘宝App跳转)

发布时间:2020-03-05 20:21:11 来源:网络 阅读:1090 作者:laiguofengg 栏目:移动开发

制作目的

  • 想要自定义系统转场动画速度
  • 放弃不顺畅的 NavigationBar 隐藏消失
  • 干脆直接干掉每个页面的 NavigationBar,在使用 UINavigationController 管理的同时,每个页面的 NavigationBar 都使用自定义的 UIView, 这样既定制程度高又可以在不需要 NavigationBar 的页面无缝对接,包括一些之前 NavigationBar 动画也可以更轻松的利用自定义的 UIView 的适配动画来更灵活的实现

实现功能

  • 可以设置一个自己认为舒服的速度进行转场动画(该动画模仿系统转场动画效果,如果需要其他转场动画可以替换我的 LGFTransition 类,或者修改 LGFTransition 类的代码)
  • 这个动画速度同时也舒服的作用到边缘手势拖动 POP 返回上

使用方式

  • pod 'LGFTransition' 或者 LGFTransition

  • 接着在 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 效果展示

UINavigationController 自定义转场动画(模仿淘宝App跳转)

Modal 效果展示

UINavigationController 自定义转场动画(模仿淘宝App跳转)

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI