UIView animateWithDuration - 如何检查动画视图是否被触摸?

时间:2015-06-07 18:45:14

标签: ios objective-c animation uiview

我有一个UIView像门一样动画,不断被打开和关闭。我想检查的是,如果用户触摸了视图中期动画。我添加了UIViewAnimationOptionAllowUserInteraction。我的问题是我希望触摸是动态的。因此,当门以70%关闭并且用户以90%触摸屏幕时,它不应该接触到触摸。

UIViewAnimationOptionAllowUserInteraction

编辑:忘记提及我在UIView上使用UITapGestureRecognizer

我的代码:

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

}

0 个答案:

没有答案
相关问题