Wei
Wei

Reputation: 3482

UINavigationController interactivePopGestureRecognizer working abnormal in iOS7

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?

Upvotes: 16

Views: 20489

Answers (3)

Bruno
Bruno

Reputation: 1592

Add in Class Controller "UIGestureRecognizerDelegate"

in viewDidAppear add

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    
    self.navigationController?.interactivePopGestureRecognizer.delegate =  self
}

=)

Upvotes: 5

Ortwin Gentz
Ortwin Gentz

Reputation: 54151

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

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return !(otherGestureRecognizer is UIPanGestureRecognizer)
}

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.

Upvotes: 5

Wei
Wei

Reputation: 3482

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];
}

Upvotes: 29

Related Questions