ios 界面卡死问题

作者: 小生不怕 | 来源:发表于2017-05-22 14:01 被阅读1237次

发现问题

前阶段经常收到反馈,说app界面偶尔会出现卡死的问题,又没有log任何信息,也不抛任何异常和崩溃;切换到后台,再回来有时又回恢复正常了!烦死了。

经过对比几次出现异常的时机和场所,发现多在一级页面跳转到二级页面,Tabbar卡死,点击其他地方也没反应。引发这一问题的导火索就是在一级页面做了侧滑的动作!!

问题分析

我的app侧滑功能用的是interactivePopGestureRecognizer这个玩意儿,是iOS7才开始有的。侧滑时,将导航栏控制器堆栈上最顶部的试图控制器移除掉,当只有一个rootViewController移除,就会出现问题。我的app中有个基类baseViewController,所以我需要改造它,变成默认是开启侧滑的,当不需要侧滑时也可以关掉。

问题解决

1. BaseViewController暴露一个属性,默认开启侧滑

@interfaceBaseViewController :UIViewController

@property(nonatomic,assign)BOOL disAbleSideslip;/**<是否禁止侧滑*/

@end

2.设置代理

@interface BaseViewController()<UIGestureRecognizerDelegate>

@end

- (void)viewDidLoad

{

[superviewDidLoad];

//加上此句,支持自定义左侧返回按钮后,仍旧支持侧滑pop功能self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

}

3.实现代理方法

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer

{

return !self.disAbleSideslip;

}

4.继承BaseViewController使用

如果该ViewController是导航栏的RootViewController disAbleSldeslip属性就设置为YES,就不会有界面卡死问题。如果指定某些界面也不需要侧滑功能也一样,初始化ViewController时disAbleSideslip设置为YES

TestViewController *vc = [TestViewController new]; 

vc.disAbleSideslip=YES;

UINavigationController*navVC = [[UINavigationControlleralloc]initWithRootViewController:vc];

[self presentViewController:navVC animated:YES completion:nil];

相关文章

网友评论

    本文标题:ios 界面卡死问题

    本文链接:https://www.haomeiwen.com/subject/zpubxxtx.html