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.
Share
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
UISwipeGestureRecognizerto 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
UIGestureRecognizersfor 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
UIGestureRecognizerscan manage everything for you?