Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a step by step guide on how to implement gesture recognizers in your class:</p> <ol> <li><p>Conform your class to <code>UIGestureRecognizerDelegate</code> protocol.</p></li> <li><p>Instantiate the gesture recognizer. For example, to instantiate a <code>UITapGestureRecognizer</code>, we will do:</p> <pre><code>UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)]; </code></pre> <p>Here, action is the selector which will handle the gesture. Here, our selector handleTapFrom will look something like:</p> <pre><code>- (void) handleTapFrom: (UITapGestureRecognizer *)recognizer { //Code to handle the gesture } </code></pre> <p>The argument to the selector is the gesture recognizer. We can use this gesture recognizer to access its properties, for example, we can find the state of the gesture recognizer, like, <code>UIGestureRecognizerStateBegan</code>, <code>UIGestureRecognizerStateEnded</code>, etc.</p></li> <li><p>Set the desired properties on the instantiated gesture recognizer. For example, for a <code>UITapGestureRecognizer</code>, we can set the properties <code>numberOfTapsRequired</code>, and <code>numberOfTouchesRequired</code>.</p></li> <li><p>Add the gesture recognizer to the view you want to detect gestures for. In our sample code (I will be sharing that code for your reference), we will add gesture recognizers to an imageView with the following line of code:</p> <pre><code>[self.imageView addGestureRecognizer:tapGestureRecognizer]; </code></pre></li> <li><p>After adding the gesture recognizer to the view, set the delegate for the gesture recognizer, i.e. the class which will handle all the gesture recognizer stuff. In our sample code, it would be like:</p> <pre><code>tapGestureRecognizer.delegate = self; </code></pre> <p><strong>Note:</strong> Assign the delegate after adding the gesture recognizer to the view. Otherwise, the action method won’t be called.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload