1

I've got a view on the bottom of my ViewController ( similar to Google Maps Bottom Sheet ). The goal is:

  1. When panning up, the view moves towards the pan direction ( essentially follows the finger), when panning ends, the view goes fullscreen. So far so good, all works.

  2. Adding swipe gestures. When swiping up, the view should go full screen.

The issue is that by definition, a swiping gesture is a pan gesture but not the other way around. So unless i go really slow with my panning , the swipe gesture will trigger and the view will go full screen even though im still dragging on the screen.

Simply panning up doesnt look much like the kind of swipe im looking for. The swipe gesture im describing should only trigger if the user "flicked" the view momentarily. If they keep on panning the pan gesture should take precedence.

Any ideas how to achieve this? For reference you could check tap on a pin on google maps on either android or ios.

Its a little hard to describe without showing so if it helps im very open to clarify things.

UPDATES

  1. I think the distinction for a swipe that would override the pan as im describing is that it a) took a short amount of time to complete b)the gesture ended with the user lifting the finger off the screen c) (maybe wrong ) the area traversed should not be too big. Sounds a lot like a flick to me..
Return-1
  • 2,329
  • 3
  • 21
  • 56
  • have you tried shouldRecognizeSimultaneously `func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true }` – luckyShubhra Sep 05 '17 at 08:16
  • 1
    you can also make use of shouldRequireFailureOf method. `func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true }` – luckyShubhra Sep 05 '17 at 08:19

2 Answers2

0

If you cannot describe the difference between the two gestures in clearly defined terms then it will be difficult to tell the UIGestureRecognizer how to do so. In addition, it is possible that your user will have difficulty figuring out how to properly interact with the screen if your gestures are too similar or complex.

That being said, you may be able to distinguish between a "swipe" and a "pan" by checking the gesture's velocity. You should be able to play around with the UIGestureRecognizerDelegate methods and achieve the effect you want.

Navillus
  • 307
  • 1
  • 9
  • 1
    I guess what im looking for a "flick" gesture that the system doesnt seem to support. I know custom gestures are usually a nono however , as im trying to replicate the functionality provided in google maps (when tapping on a pin ) to bring about something familiar to the map part of the app i dont see much other way than going custom. In other words, maybe the swipe gesture just isnt the solution to the problem im looking at. – Return-1 Sep 05 '17 at 08:09
  • 1
    This post might help you https://stackoverflow.com/questions/9898627/what-is-the-difference-between-pan-and-swipe-in-ios. Ultimately, these gestures are capable of doing whatever you want, assuming there are clear distinguishing characteristics for each gesture. However, you will have to play around with the delegate methods to achieve the effect, and it may take a lot of tweaking. – Navillus Sep 05 '17 at 08:11
  • From your update it seems like you know specifically what you want, which is a good first step. – Navillus Sep 05 '17 at 08:14
0

Ok i've achieved what was needed. The short answer is that i was looking for a "flick" gesture instead of a pan gesture. Generally its a nono to add custom gestures but as im replicating the google maps bottom sheet component for ios, it would appear that a custom gesture is the only way.

Using Navillus's comment, I added a velocity and gesture end check in the pan recogniser. The result looked like this:

if(recognizer.state == .ended){
        if(recognizer.velocity(in: self).y > CGFloat(500) ){
            self.pullUpViewSetMode_SUMMARY()
            return;
        }

        if(recognizer.velocity(in: self).y < CGFloat(-500) ){
            self.pullUpViewSetMode_FULL()
            return;
        }
}
//the rest of the pan handling code, namely translating the view up and up follows here

Hope this helps somebody.

Return-1
  • 2,329
  • 3
  • 21
  • 56