gpt4 book ai didi

ios - 当我为 UIImageView 设置动画时,UITapGestureRecognizer 不起作用

转载 作者:可可西里 更新时间:2023-11-01 03:03:25 26 4
gpt4 key购买 nike

当我想为 UIImageView 设置动画时,添加到它的 UITapGestureRecognizer 无法工作。为什么???

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

最佳答案

您需要在动画期间允许用户交互。

UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;

关于ios - 当我为 UIImageView 设置动画时,UITapGestureRecognizer 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13686429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com