首页 > 其他 > 详细

返回手势导致页面卡死并且UI错乱的问题解决

时间:2019-09-05 12:56:24      阅读:96      评论:0      收藏:0      [点我收藏+]

问题记录:在做了部分页面的转场动画之后,返回手势不灵了,快速连续返回的话会卡住,App退到后台再重新激活之后页面不卡了,但是UI错乱.

 

解决方案:

1. 在UINavigationController子类实现代理UIGestureRecognizerDelegate,并在viewDidLoad方法中增加代理设置:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.interactivePopGestureRecognizer.delegate = self;
}

 

2. 重写UINavigationController的push方法,在方法中关闭手势:

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
   if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    // 为了解决部分页面加了转场动画手势返回卡死的bug
    // 在UINavigationController代理方法didShowViewController中设置enable = YES
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = NO;
    }
    [super pushViewController:viewController animated:animated];
 }

 

 3. 在UINavigationControllerDelegate代理类中实现navigationController:didShowViewController:animated:方法:

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 为了解决手势返回卡住的bug
    // 在NavigationController中重写push方法禁用返回手势,此处打开
    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

 

返回手势导致页面卡死并且UI错乱的问题解决

原文:https://www.cnblogs.com/GaryZhang/p/11460747.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!