Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>UILongPressGestureRecognizer</code> knows only about the minimum number of touches - by default, one finger - and putting down another finger later is not going to have much effect. Trying this on a real phone with a single touch required sees the initial touch causing a transition in the Recognizer to state 1. Either moving the first finger sideways, or touching down a second finger, causes a transition to state 2. Lifting the first finger to touch down causes a transition to state 3 and ends the gesture.</p> <p>I added a second <code>UILongPressGestureRecognizer</code> to the same view as the first one above, but gave this one a minimum two-touch requirement. Like so:</p> <pre><code> UILongPressGestureRecognizer *lpgr1 = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(lpgr1Method:)]; UILongPressGestureRecognizer *lpgr2 = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(lpgr2Method:)]; lpgr2.numberOfTouchesRequired = 2; [self.view addGestureRecognizer:lpgr1]; [self.view addGestureRecognizer:lpgr2]; // ... - (void)lpgr1Method:(UIGestureRecognizer *)gestureRecognizer { UIGestureRecognizerState state = gestureRecognizer.state; self.stateLabel.text = [NSString stringWithFormat:@"%d", (int)state]; } - (void)lpgr2Method:(UIGestureRecognizer *)gestureRecognizer { UIGestureRecognizerState state = gestureRecognizer.state; self.stateLabel2.text = [NSString stringWithFormat:@"%d", (int)state]; } </code></pre> <p>If I first touch down with one finger and hold that, <code>lpgr1</code> goes to state 1. If I then touch down with a second finger and hold that, <code>lpgr1</code> goes to state 2. <code>lpgr2</code> does not fire at all.</p> <p>If I touch down with two fingers at once and hold that, <code>lpgr2</code> fires, and <code>lpgr1</code> never fires.</p> <p>So it looks as though adding two recognizers to the whole view is just confusing, and won't achieve the result you want, no matter how you program it. The proper approach is thus to write your own subclass of <code>UIGestureRecognizer</code>, I suspect.</p> <p><strong>Edit:</strong> I also tried this: </p> <pre><code>lpgr2.delegate = self; lpgr1.delegate = self; // ... - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return true; } </code></pre> <p>and that does allow both recognizers to fire at the same time, and recognize that the second finger has touched down. However, <code>lpgr1</code> ends as soon as the first finger is removed. I couldn't make this do quite what you wanted, either. I'd write the subclass, but my attention is required elsewhere. Good luck!</p>
    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.
 

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