UINavigationController interactivePopGestureRecogn

2019-01-17 01:50发布

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?

4条回答
一夜七次
2楼-- · 2019-01-17 02:07

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];
}
查看更多
手持菜刀,她持情操
3楼-- · 2019-01-17 02:16

Add in Class Controller "UIGestureRecognizerDelegate"

in ViewDidApper add

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

    self.navigationController?.interactivePopGestureRecognizer.delegate =  self
}

=)

查看更多
够拽才男人
4楼-- · 2019-01-17 02:21

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.

查看更多
forever°为你锁心
5楼-- · 2019-01-17 02:24

The solution Wei posted, did not work for me. My screens froze loosing recognition of any gestures at all.

I am now using AHKNavigationController by Arkadiusz Holko http://holko.pl/ios/2014/04/06/interactive-pop-gesture/

Took me 30 seconds to get via CocoaPods and another 30 seconds to setup as the custom class of my NavigatonController via storyboards.

查看更多
登录 后发表回答