gpt4 book ai didi

ios7 - 如何仅在一个 View 中禁用 iOS 7 中的后退手势

转载 作者:行者123 更新时间:2023-12-04 16:15:24 26 4
gpt4 key购买 nike

我正在尝试使用以下代码集禁用我的 View Controller 的后退手势。

FirstViewController.m ,我正在设置 interactivePopGestureRecognizer 的代表

- (void) viewWillLoad {

// Other stuff..
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}

然后执行 <UIGestureRecognizerDelegate>方法并返回 NO .
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

return NO;
}

在 dealloc 中,我将委托(delegate)设置为 nil。 (我在某处读过,在 iOS 7 中,您必须手动将代表设置为 nil)
- (void)dealloc {

self.navigationController.delegate = nil;
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}

这适用于 FirstViewController .但是当我推 SecondViewController对此,手势也不起作用。如何仅在 FirstViewController 中禁用手势?

还有当我弹出 FirstViewController前往 RootViewController然后尝试推送 FirstViewController再次,我得到对象释放错误:
[FirstViewController gestureRecognizer:shouldReceiveTouch:]: message sent to deallocated instance 0x14ed0280

除了将代表设置为零之外,我还需要做什么?还是我把它放在了错误的地方?

最佳答案

在您的 FirstViewController 中尝试以下未经测试的代码:

-(void) viewWillAppear:(BOOL)animated 
{
[super viewWillAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

-(void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}

关于ios7 - 如何仅在一个 View 中禁用 iOS 7 中的后退手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19108601/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com