Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISwipeGestureRecognizer location

I need to trigger a different event depending on whether the user swipes the top of the screen, the middle of the screen, or the bottom of the screen. I'm trying to figure out the best/easiest way to do this, since I'm pretty sure that there is no way to get the location from UISwipeGestureRecognizer.

The first option is to create my own swipe recognizer using the 'touches' methods. This seems like it would be very difficult (trying to differentiate between a swipe and a drag, for example).

The second possibility is to get the location from one of the 'touches' methods (touchesBegan for example), and to somehow associate that with the swipe. Maybe set a timer in touchesBegan and then if the swipe recognizer fires within half-a-second or so I'll know that swipe was connected to that touch.

The third possibility I can think of is to lay 3 transparent subviews on top of my view and add a different swipe recognizer to each view. This seems like the best way to me except that transparent views don't recognize touch/swipe events. So how can I work around this?

Any suggestions? Thanks.

like image 320
user617123 Avatar asked Dec 17 '22 15:12

user617123


1 Answers

You could probably you use the locationOfTouch method of UISwipeGestureRecognizer.

CGPoint pt = [recognizer locationOfTouch:0 inView:view];

I believe this will give you the original x,y coordinates of the touch that initiated the gesture.

like image 154
Matt MacLean Avatar answered Dec 21 '22 23:12

Matt MacLean