Note that there are some explanatory texts on larger screens.

plurals
  1. POUITapGestureRecognizer is ignored after moving outside view and back in
    primarykey
    data
    text
    <p>I have a <code>UILabel</code> as child in my <code>UIView</code>. I use it as status panel which slides out of the view if nothing has to be shown. I do that by simply animating it to origin.y of minus the height of the label.</p> <p>As soon as a message has to be displayed, I slide the label back into the view. After a delay of a few seconds it slides back out. That works fine.</p> <p>I also added a <code>UITapGestureRecognizer</code> to the label, so the user can dismiss the message right away without waiting for it to go away automatically.</p> <p>My problem is, that the gesture recognizer is not firing as once the label moved outside the view. I initialize and add the gesture recognizer when the label is completely inside the view and visible. It works as expected the first time. But when the message comes back in, the gesture recognizer seems to be removed or disabled.</p> <p>I also tried to add a gr every time the label is completely on the screen in the complete block of my animation, but that didn't help either.</p> <p>Can someone explain to me what happens here and how I can make the recognizer work all the time?</p> <p>If you need and further information let me know.</p> <h3>UPDATE</h3> <p>I did some further testing and I get this when I log the lblError.gestureRecognizers in the showError call:</p> <pre><code>&lt;UITapGestureRecognizer: 0x6b153f0; state = Possible; view = &lt;UILabel 0x6b14fa0&gt;; target= &lt;(action=dismissError:, target=&lt;OptionViewController 0x686d2a0&gt;)&gt;&gt; </code></pre> <p>It's exactly the same I get right after it's creation. So it's still there and I guess the touch events don't get to it.</p> <h3>UPDATE 2</h3> <p>I get a step further.</p> <p>The problem seems to be that I move the label to y coordinate 0. That's probably a bug in the <code>GestureRecognizer</code> code because when I set it 0.1 it works!</p> <p>Looks like the system "thinks" that the label is not in the view and therefore disables the touch handling or something. ^^</p> <p>This solves one half of the problem but creates a new one on the other side. Now that the gesture recognizer works, the delayed move out animation don't get triggered anymore. </p> <p>So I think the real problem is, that the move out animation is triggered right after the move in. Even though it is delayed, it prevents the label from receiving any kind of touch events.</p> <h3>The code</h3> <p>// add gesture recognizer (in viewDidLoad)</p> <pre><code>UITapGestureRecognizer *errorDismissGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissError:)]; [lblError addGestureRecognizer:errorDismissGesture]; // display error - (void)showError:(NSString *)message { [lblError setText:message]; [UIView animateWithDuration:0.5 animations:^(void) { CGRect frame = lblError.frame; frame.size.width = self.view.bounds.size.width; frame.origin.y = 0; lblError.frame = frame; } completion:^(BOOL finished) { [UIView animateWithDuration:0.5 delay:2.0 options:UIViewAnimationOptionCurveEaseOut animations:^(void) { CGRect frame = lblError.frame; frame.origin.y = -40.0f; lblError.frame = frame; } completion:^(BOOL finished) {}]; }]; } - (void)dismissError:(UIGestureRecognizer *)sender { [UIView animateWithDuration:0.3 animations:^(void) { CGRect frame = lblError.frame; frame.origin.y = -40.0; lblError.frame = frame; } completion:^(BOOL finished) {}]; } </code></pre> <p>Thanks and Greets, Thomas</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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