Reputation: 139
I have two questions:
Can I implement gesture recogniser that inherits from UISwipeGestureRecognizer
and add logic to the UIEvent
handlers?
Can I implement UIGestureRecognizer
without attaching it to a UIView
? Meaning, I will analyze and manage the UIEvent
events and call the proper selector (touchesBegan
, touchesMoved
, touchesEnded
, touchesCancelled
)?
In the meantime I have problems reseting the gesture recogniser when the state is UIGestureRecognizerStateEnded
.
Upvotes: 1
Views: 322
Reputation: 437392
You asked:
Can I implement gesture recogniser that inherits from
UISwipeGestureRecognizer
and add logic to theUIEvent
handlers?
Yes. See Creating a Custom Gesture Recognizer in the Event Handling Guide for iOS. Also see WWDC 2010 session 121 - Advanced Gesture Recognition. It probably depends upon what you want to do, though, and you should see if you can accomplish what you want by configuring the standard swipe gesture's direction
and numberOfTouches
parameters. I've done more subclassing on continuous gestures like UIPanGestureRecognizer
, but I see no reason why you couldn't do it on a swipe, too.
Can I implement
UIGestureRecognizer
without attaching it to aUIView
? Meaning, I will analyze and manage theUIEvent
events and call the proper selector (touchesBegan
,touchesMoved
,touchesEnded
,touchesCancelled
)?
No. Obviously you can create one, but it just won't receive any of the events until it's added to a UIView
and that view receives touches.
In the meantime I have problems reseting the gesture recogniser when the state is
UIGestureRecognizerStateEnded
.
You'd have to submit a new question providing a relevant code snippet for us to help you on that one. In general, you'd do any post-gesture cleanup when your handler is called for UIGestureRecognizerStateEnded
(and UIGestureRecognizerStateCancelled
or UIGestureRecognizerStateFailed
) and you'd initialize everything for the next gesture when you receive the next UIGestureRecognizerStateBegan
.
Upvotes: 1