当我为UIImageView设置动画时,UITapGestureRecognizer不起作用 [英] UITapGestureRecognizer not work when I animate the UIImageView
本文介绍了当我为UIImageView设置动画时,UITapGestureRecognizer不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我想为 UIImageView
设置动画时,添加到它的 UITapGestureRecognizer
无效。为什么???
When I want to animate the UIImageView
, the UITapGestureRecognizer
added to it can not work. WHY???
-(void) testTap:(id)sender {
NSLog(@"Test tap...");
}
-(void) testSlide {
UITapGestureRecognizer* testTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(testTap:)] autorelease];
testTap.numberOfTapsRequired = 2;
UIImageView* imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tip_slide"]] autorelease];
[imageView setFrame:CGRectMake(40, 40, 200, 200)];
imageView.userInteractionEnabled = YES;
imageView.multipleTouchEnabled = YES;
[imageView addGestureRecognizer:testTap];
[self.view addSubview:imageView];
// When I add the following code, the UITapGestureRecognizer will not work. WHY???
imageView.alpha = 0;
CGAffineTransform t = imageView.transform;
if (CGAffineTransformIsIdentity(t)) {
UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut;
[UIView animateWithDuration:1.0 delay:0 options:options animations:^{
imageView.alpha = 1.0;
} completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:1.0 delay:2.0 options:options animations:^{
imageView.alpha = 0.4;
} completion:^(BOOL finished) {
if (finished) {
[imageView removeFromSuperview];
}
}];
}
}];
}
}
推荐答案
你需要在动画期间允许用户交互。
You need to allow user interaction during animation.
UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;
这篇关于当我为UIImageView设置动画时,UITapGestureRecognizer不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文