0

我有多个图像要使用交叉溶解动画在 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) {
                    }
     ];
}

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

4

1 回答 1

4

像这样在选项中设置 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) {
                    }
     ];
于 2013-06-06T10:03:37.817 回答