1

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];
                                                  }
                                              }];
                         }
                     }];

}
Peter Lendvay
  • 565
  • 4
  • 22
  • and where is the problem? does the tapgesturerecognizer not fire? – luk2302 Jun 07 '15 at 19:04
  • Is the following what you want? If the animation is from 100 to 10 and is at 50% - therefore having a width of 55 you want a touch at 60 (not valid) or a touch at 50 (valid)!? – luk2302 Jun 07 '15 at 19:19
  • If the touch is at 60 it shouldn't be valid, and at 50 should be, yes. The tapgesturerecognizer does fire, but when the door is closing it acts like if it was already closed, and while it opens its acts like its already opened. – Peter Lendvay Jun 07 '15 at 19:27
  • 1
    You might want to take a look at http://stackoverflow.com/questions/9523981/uiviewanimationoptionallowuserinteraction-not-working and http://stackoverflow.com/questions/8346100/uibutton-cant-be-touched-while-animated-with-uiview-animatewithduration – luk2302 Jun 07 '15 at 19:31
  • Works perfect! Thanks – Peter Lendvay Jun 07 '15 at 19:40

0 Answers0