Touches getting lost when I animate inside of touchesBegan

928 views Asked by At

I'd like to have 4 UIViews on the screen and animate their background color when touched and change it back when touches end.

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    [UIView animateWithDuration:0.1
        animations:^{
            self.backgroundColor = altColor;
        }];
}

Unfortunately, when I perform this animation in touchesBegan - touchesEnded won't fire unless the touch ended after the animation completed. This means that touchesEnded gets lost for touches during the animation.

In addition, rapidly hitting the UIView doesn't result in multiple touchesBegan invocations. It seems that no new touches are received until the animation (spawned in the first touch) completes.

How can I respond to all touches with animations? I'd actually like each new touch to interrupt the previous animation ... and start it over again.

2

There are 2 answers

0
Luther Baker On BEST ANSWER

Looks like I need to set an option on the block animation

options:UIViewAnimationOptionAllowUserInteraction
0
Luther Baker On

Turns out that this older type of animation doesn't seem to block new touchesBegan or touchesEnded:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    [UIView beginAnimations:@"touchesBegan" context:nil];
    self.backgroundColor = altColor;
    [UIView commitAnimations];
}