gpt4 book ai didi

ios - 动画期间的 UITapGestureRecongnizer 失败

转载 作者:行者123 更新时间:2023-11-29 02:25:28 25 4
gpt4 key购买 nike

我正在使用以下代码生成可触摸的图像。

我在这里看到一些帖子说 UIButton 不能在动画期间使用,所以我改为使用点击手势。我还在选项中添加了 UIViewAnimationOptionAllowUserInteraction。但我仍然无法让它发挥作用。我可以知道原因和任何解决方案吗?

hit1 = [[UIImageView alloc]initWithFrame:CGRectMake(539,227,50,50)];
hit1.image=[UIImage imageNamed:@"roles.png"];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hitenermy:)];
[hit1 addGestureRecognizer:singleTap];
[hit1 setMultipleTouchEnabled:YES];
[hit1 setUserInteractionEnabled:YES];
hit1.userInteractionEnabled=YES;


[self.view addSubview:hit1];
[hit1 addGestureRecognizer:singleTap];
UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;

[UIView animateWithDuration:15.0
delay:1.0
options:options
animations:^{
hit1.center = CGPointMake(hit1.center.x-210, hit1.center.y-60);

}
completion:^(BOOL finished){

}];

最佳答案

您可以使用 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 获取触摸事件。我已经展示了单个 imageView,但如果存在多个 imageView,那么您可以使用标签来区分它们。

您可以从:UIButton can't be touched while animated with UIView animateWithDuration 获得更多信息

- (void)viewDidLoad
{
[super viewDidLoad];

hit1 = [[UIImageView alloc]initWithFrame:CGRectMake(539,227,50,50)];
hit1.image=[UIImage imageNamed:@"roles.png"];

[self.view addSubview:hit1];

UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;

[UIView animateWithDuration:15.0
delay:1.0
options:options
animations:^{
hit1.center = CGPointMake(hit1.center.x-210, hit1.center.y-60);
}
completion:^(BOOL finished){

}];
}



- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
for (UIImageView *imageView in self.view.subviews)
{
if ([imageView.layer.presentationLayer hitTest:touchLocation])
{
NSLog(@"Clicked");
break;
}
}
}

关于ios - 动画期间的 UITapGestureRecongnizer 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27598805/

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