I'm having a UIView being animated like a door, constantly being opened and closed sequentially. What I'm trying to check is, if the user touched view mid animation. I've added UIViewAnimationOptionAllowUserInteraction
. My problem is that I want the touch to be dynamic. So when the door is being closed at 70% and the user touches the screen at 90%, it should not receive the touch.
UIViewAnimationOptionAllowUserInteraction
EDIT: Forgot to mention I was using UITapGestureRecognizer
on the UIView.
My code:
-(void)animateWithDuration:(float)duration{
[self.view layoutIfNeeded];
self.doorWidth.constant = closedWidth;
[UIView animateWithDuration:duration
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionAllowAnimatedContent)
animations:^{
[self.view layoutIfNeeded];
}
completion:^(BOOL finished){
if (!isStopped) {
self.doorWidth.constant = openWidth;
[UIView animateWithDuration:duration
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionAllowAnimatedContent)
animations:^{
[self.view layoutIfNeeded];
}
completion:^(BOOL finished){
if (finished) {
isOpen = false;
float randomTime = ((float)arc4random() / ARC4RANDOM_MAX)+0.3;
[self animateWithDuration:randomTime];
}
}];
}
}];
}