在我的应用程序中,我有不同的控制器。当我将controller1推到导航控制器并向后滑动时,一切正常。但是,如果我推动导航控制器1,并进入controller1推控制器2并尝试向后滑动,我得到一个冻结的应用程序。如果通过后退按钮返回一切正常。
我怎样才能发现问题?
答案 0 :(得分:33)
使用滑动到弹出手势时,我遇到了与冻结界面类似的问题。
在我的情况下问题是在controller1.viewDidAppear我禁用滑动手势:self.navigationController.interactivePopGestureRecognizer.enabled = NO
。因此,当用户开始从contorller2向后滑动时,触发了controller1.viewDidAppear并且在其工作期间禁用了手势。
我通过在controller1中设置self.navigationController.interactivePopGestureRecognizer.delegate = self
并实现gestureRecognizerShouldBegin:
来解决此问题,而不是禁用手势识别器:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] &&
gestureRecognizer == self.navigationController.interactivePopGestureRecognizer) {
return NO;
}
return YES;
}
答案 1 :(得分:15)
我的解决方案是向导航控制器添加一个委托。然后仅在根视图控制器中禁用弹出手势识别器。 YMMV。
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
BOOL isRootVC = viewController == navigationController.viewControllers.firstObject;
navigationController.interactivePopGestureRecognizer.enabled = !isRootVC;
}
答案 2 :(得分:2)
当在第一个控制器上向后轻扫,然后在tableViewCell上轻按时,我遇到问题,我认为从边缘进行强制触摸滑动是在切换应用程序之前注册了向后滑动,有时UI卡住了,有时当我向后滑动时它开始在目标控制器上输入。我用此扩展程序解决了问题,它对我有用,这是简单的解决方案。雨燕4.2
extension UINavigationController:UINavigationControllerDelegate {
open override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
public func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
if responds(to: #selector(getter: self.interactivePopGestureRecognizer)) {
if viewControllers.count > 1 {
interactivePopGestureRecognizer?.isEnabled = true
} else {
interactivePopGestureRecognizer?.isEnabled = false
}
}
}
}
答案 3 :(得分:1)
迅速4:
设置代表,
gem sources -a https://rubygems.org/
实施委托方法,
sudo gem install
答案 4 :(得分:0)
我有同样的问题,我发现下面的解决方案。添加以下控制器
#import <UIKit/UIKit.h>
@interface CBNavigationController : UINavigationController <UIGestureRecognizerDelegate,UINavigationControllerDelegate>
@end
#import "CBNavigationController.h"
@interface CBNavigationController ()
@end
@implementation CBNavigationController
- (void)viewDidLoad
{
NSLog(@"%s",__FUNCTION__);
__weak CBNavigationController *weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.interactivePopGestureRecognizer.delegate = weakSelf;
self.delegate = weakSelf;
}
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(@"%s",__FUNCTION__);
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
self.interactivePopGestureRecognizer.enabled = NO;
[super pushViewController:viewController animated:animated];
}
#pragma mark UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animate
{
NSLog(@"%s",__FUNCTION__);
// Enable the gesture again once the new controller is shown
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
self.interactivePopGestureRecognizer.enabled = YES;
}
@end
可参考以下链接
http://keighl.com/post/ios7-interactive-pop-gesture-custom-back-button/
答案 5 :(得分:0)
我的解决方案是在self.navigationController.interactivePopGestureRecognizer.delegate
和selfImplementDelegate
SystemDelegate
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[_tableView reloadData];
_oldReturnDelegate = self.navigationController.interactivePopGestureRecognizer.delegate;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
- (void)viewWillDisappear:(BOOL)animated
{
self.navigationController.interactivePopGestureRecognizer.delegate = _oldReturnDelegate;
[super viewWillDisappear:animated];
}
答案 6 :(得分:0)
我建议你试一试。这对我来说非常适合。您仍然可以享受交互式滑动。
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] &&
gestureRecognizer == self.navigationController.interactivePopGestureRecognizer) {
if(self.navigationController.viewControllers.count<=1)
{
return NO;
}
}
return YES;
}
答案 7 :(得分:0)
将此代码添加到根导航控制器
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return self == self.navigationController?.topViewController ? false : true
}
添加UIGestureRecognizerDelegate协议
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
答案 8 :(得分:-1)
我通过UINavigationController interactivePopGestureRecognizer working abnormal in iOS7解决了我的问题并设置了self.navigationController.interactivePopGestureRecognizer.delegate = self;
在每个viewcontroller上
- (void)viewWillAppear:(BOOL)animated