Gesture Recognizers in iOS | raywenderlich.com

Touch interaction is a fundamental component of iOS and UIGestureRecognizer is the key to easy-to-use gestures beyond simple button taps. Learn about it here!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9225-gesture-recognizers-in-ios

Hi

I’m working through the custom gesture recognisers Video and finding that the action isn’t triggered even if the gesture is recognised. LookIng at the documentation, it seems that the state variable is read only In the class and one must import the sub classing version of the header. But even this seems to have the state redefinition removed even if the comment for it is still in place. What gives ? Any suggestions welcome.

Thanks

Hello again,

I figured out what was wrong with my version of the program, but I wold still like to know why the documentation says that the state variable in UIGestureRecognizer is readonly, confirmed by looking at the header where it does seem to be defined as readonly, and recommends that if sub-classing, one must include the appropriate header etc. whereas you don’t and it seems it works without needing to do anything. Why the discrepancy ?

Thanks for your help.

1 Like

I don’t know enough about Objective-C to tell you what mechanism made what you’re asking about possible in that language.

Screen Shot 2020-04-25 at 6.24.39 PM

In C#, for example, this is possible with the new keyword.

Swift doesn’t have the feature, so there’s no reason I know of to bother with UIGestureRecognizerSubclass.

Hi

Thanks for getting back. So this is an objective-c throwback. Just for my education, why does it say :

open var state: UIGestureRecognizer.State { get } // the current state of the gesture recognizer

in the header ‘UIGestureRecognizer’ ? Its a readonly variable. How come we can change it in your code then ?

Thanks

The interface generation doesn’t know how to deal with things that can’t be represented in Swift. What you’re seeing is false.

e.g. This always works.

UIGestureRecognizer().state = .recognized

At least the docs are accurate. Apple Developer Documentation

I see. Ok. Looks like they haven’t updated bits of the documentation. Thanks Jessy.