0

I have just managed to implement detection of a swipe gesture for my app. However I would like to confine the area where the gesture is valid. Thinking about this I came up with a possible solution which would be to check whether the start & finish coordinates are within some area. I was just wondering if there's a better or preferred method of doing something like this.

1 Answers1

2

Simply create an invisible UIView (= with transparent background) and set its frame so it encloses the region you want to detect the gesture into.

Then, simply add a UISwipeGestureRecognizer to that view, and you are done.

Read the generic UIGestureRecognizer Class Reference and the part of the Event Handling Guide for iOS that talks about UIGestureRecognizers for more info.


Of course you could also manage the detection of the swipe gesture by yourself using custom code like explained here in the very same guide but why bother when UIGestureRecognizers can manage everything for you?

AliSoftware
  • 32,623
  • 6
  • 82
  • 77