【问题标题】:iOS: UIImageView doesn't respond to tap gestures between animationsiOS:UIImageView 不响应动画之间的点击手势
【发布时间】:2013-06-06 09:57:54
【问题描述】:

我有多个图像要使用交叉溶解动画在 imageview 中显示,并且点击图像会显示有关图像的详细信息。以下是代码工作,但是当它从一个图像动画到另一个图像时,点击 imageview 失败。

将单击手势识别器附加到 UIImageview 并启动动画计时器的代码。

    self.imageView.userInteractionEnabled = YES;
    self.singleTapGestureRecogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showDetails)];
    self.singleTapGestureRecogniser.numberOfTapsRequired = 1;
    self.singleTapGestureRecogniser.cancelsTouchesInView = NO;

    [self.imageView addGestureRecognizer:self.singleTapGestureRecogniser];

    [self startAnimationTimer];

- (void)startAnimationTimer
{
    if(!self.timer && ![self.timer isValid]) {
        self.timer  =  [NSTimer scheduledTimerWithTimeInterval:5.0
                                target:self
                                selector:@selector(startAnimation)
                                userInfo:nil
                                repeats:YES];
        [self.timer fire];
    }
}

单击 imageview 可以正常工作,除非正在执行以下代码!我必须点按 3-4 次才能打开有关图像的详细信息。

- (void)startAnimation
{
    [UIView transitionWithView:self.imageView duration:2.0
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^ {
                        currentImageIndex = ++currentImageIndex % self.images.count;
                        [self.imageView setImage:[[self.images objectAtIndex:currentImageIndex] image]];
                    } completion:^(BOOL finished) {
                    }
     ];
}

请有人建议我如何摆脱这个问题。

【问题讨论】:

  • 在动画时禁用用户交互并在完成动画后启用。
  • 我不想禁用用户交互。我想随时识别点击事件,包括在制作动画时。
  • 你能给我看看崩溃日志吗?
  • 我没说它崩溃了!反正它解决了。检查 Hermione333 的答案。

标签: ios ipad uiimageview uitapgesturerecognizer uiviewanimationtransition


【解决方案1】:

像这样在选项中设置 UIViewAnimationOptionAllowUserInteraction

 [UIView transitionWithView:self.imageView duration:2.0
                       options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction
                    animations:^ {
                        currentImageIndex = ++currentImageIndex % self.images.count;
                        [self.imageView setImage:[[self.images objectAtIndex:currentImageIndex] image]];
                    } completion:^(BOOL finished) {
                    }
     ];

【讨论】:

  • 太棒了!我不知道这个选项。谢谢你。 :-)
  • 对不起,我尝试立即接受,但 SO 让我等 5 分钟!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多