我使用交叉溶解动画在图像视图中显示多个图像,并在图像上显示有关图像的详细信息。以下是代码工作,但当它从一个图像动画到另一个图像时,点击图像视图失败。
将单击手势识别器附加到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];
}
}
单击图像视图可以正常工作,除非执行以下代码!我必须点击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) {
}
];
}
有人可以建议我如何摆脱这个问题。
答案 0 :(得分: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) {
}
];