我在一些视图控制器中添加了“interactivePopGestureRecognizer”,也在 topbar 上给出了返回按钮。当用户当时使用 Pop Gesture 和推送/弹出视图时,它将冻结顶部导航控制器视图。一段时间后,它会因“[viewcontroller hash]: message sent to deallocated instance”而崩溃。
方法
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
//Pop GESTURE
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = true;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
//Remove Pop Gesture
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = false;
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
DELEGATE METHOD
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
// add whatever logic you would otherwise have
return YES;
}
我有 TabBar 类型的应用程序。