Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone UIView Animation Disables UIButton Subview
    text
    copied!<p>So I've got a problem with buttons and animations. Basically, I'm animating a view using the UIView animations while also trying to listen for taps on the button inside the view. The view is just as large as the button, and the view is actually a subclass of UIImageView with an image below the button. The view is a subview of a container view placed in Interface Builder with user interaction enabled and clipping enabled. All the animation and button handling is done in this UIImageView subclass, while the <code>startFloating</code> message is sent from a separate class as needed.</p> <p>If I do no animation, the <code>buttonTapped:</code> message gets sent correctly, but during the animation it does not get sent. I've also tried implementing the <code>touchesEnded</code> method, and the same behavior occurs.</p> <p>UIImageView subclass init (I have the button filled with a color so I can see the frame gets set properly, which it does):</p> <pre><code>- (id)initWithImage:(UIImage *)image { self = [super initWithImage:image]; if (self != nil) { // ...stuffs UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom]; tapBtn.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); [tapBtn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; tapBtn.backgroundColor = [UIColor cyanColor]; [self addSubview:tapBtn]; self.userInteractionEnabled = YES; } return self; } </code></pre> <p>Animation method that starts the animation (if I don't call this the button works correctly):</p> <pre><code>- (void)startFloating { [UIView beginAnimations:@"floating" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationDuration:10.0f]; self.frame = CGRectMake(self.frame.origin.x, -self.frame.size.height, self.frame.size.width, self.frame.size.height); [UIView commitAnimations]; } </code></pre> <p>So, to be clear:</p> <ul> <li>Using the UIView animation effectively disables the button.</li> <li>Disabling the animation causes the button to work.</li> <li>The button is correctly sized and positioned on screen, and moves along with the view correctly.</li> </ul>
 

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