1

In my app, I want to detect an upwards swipe. So of course, I added a UISwipeGestureRecognizer to the view of the view controller.

As expected, this recognizer detects swipe very well. But a bad thing about this is that a swipe from bottom edge is also detected. When the user wants to open the control center:

enter image description here

a swipe is also detected. I don't want this to happen.

In other words, I want to detect all upwards swipes except those from the bottom edge of the screen.

I think I can use a UIEdgePanGestureRecognizer to detect an edge swipe as well. And when such a swipe is detected, disable the swipe recognizer. But this is barely possible right? Because who knows which recognizer detects a gesture first?

How can I do this?

P.S. I think I need to use requireGestureRecognizerToFail, but the documentation is so bad I can't fully understand.

Sweeper
  • 213,210
  • 22
  • 193
  • 313

2 Answers2

0

You can try hiding status bar so there wont be accidental control center openings. With this when user swipe from bottom, an arrow will appear. If still user wants to open control center, he/she needs to swipe again.

Try code below

override func prefersStatusBarHidden() -> Bool {
return true
}

There is one more solution for this, but I am not sure if Apple will be angry of this.

In .plist there is value named "View controller-based status bar appearance". Set it to NO

batgun
  • 1,001
  • 1
  • 9
  • 16
0

In this case you should use this delegate method

optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool

Check otherGestureRecognizer and return NO if you don't want your recogniser to fire simultaneously with it.

Try this and see whether the system calls this method with the gesture recogniser you're trying to avoid. If not, consider adding your own UIScreenEdgePanGestureRecognizer with UIRectEdge.Bottom to check against that instead.

hybridcattt
  • 3,001
  • 20
  • 37
  • I tried it and this sometimes works, but sometimes doesn't. I think it's because you can sometimes open the control center without triggering an edge pan recognizer. – Sweeper Aug 26 '16 at 08:18
  • Yes, that could be. But would your swipe gesture still fire in that case? – hybridcattt Aug 26 '16 at 08:20
  • Yes. If you start swiping from a little bit above the edge, you can open the control centre. – Sweeper Aug 26 '16 at 08:22