UINavigationController interactivePopGestureRecognizer working abnormal in iOS7

回眸只為那壹抹淺笑 提交于 2019-11-27 01:02:25

问题


In iOS7, we have a new "swipe left to right" gesture, this is a very useful feature, but now I have a problem with it.

I use this code to custom the back button in UINavigationBar.

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];

but this will disables the "swipe left to right" gesture, so I use the follow code to keep the gesture enabled.

self.navigationController.interactivePopGestureRecognizer.delegate = self

And then, I found that the gesture is working abnormal, if current ViewController has a tableView, when the tableView is scrolling, the gesture won't be triggered. Now the gesture can't be triggered easily, is there some way to fix it?


回答1:


This code can wroks well for me.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}



回答2:


Setting the interactivePopGestureRecognizer.delegate to self is only the first step. The second step is to implement

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return ![otherGestureRecognizer isKindOfClass:UIPanGestureRecognizer.class];
}

The test against the pan gesture recognizer is needed to block vertical scrolling of a scroll or table view while the interactive pop is in progress.




回答3:


Add in Class Controller "UIGestureRecognizerDelegate"

in ViewDidApper add

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    self.navigationController?.interactivePopGestureRecognizer.delegate =  self
}

=)



来源:https://stackoverflow.com/questions/20992039/uinavigationcontroller-interactivepopgesturerecognizer-working-abnormal-in-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!