gpt4 book ai didi

ios uiimageview 点击手势在动画期间不起作用

转载 作者:行者123 更新时间:2023-11-29 11:09:10 26 4
gpt4 key购买 nike

我有一个 UIImageView 是动画的并且接收一个 UITapGestureRecognizer。问题是在动画时,点击手势区域不会随 View 移动。我可以点击 View 的原始位置并识别点击手势。任何人都知道如何在 View 移动而不是在其原始位置时识别水龙头?

编辑 1:这就是我设置点击手势识别器的方式:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
tapRecognizer.cancelsTouchesInView = YES;
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.delegate = (id)self;
[imageView addGestureRecognizer:tapRecognizer];
imageView.userInteractionEnabled = YES;

自从我的动画持续几秒钟后,有没有办法让手势识别器在其路径上跟随我的 View ?我错过了设置吗?

编辑 2:这是我设置动画的代码:

    double width = backgroundImageView.frame.size.width;
double height = backgroundImageView.frame.size.height;

CGMutablePathRef path = CGPathCreateMutable();
double startX = -imageView.frame.size.width;
double startY = height/4;
double endX = 3*width;
double endY = 0;
double duration = 40;
CGPathMoveToPoint(path, NULL, startX, startY);
CGPathAddLineToPoint(path, NULL, endX, endY);
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.duration = duration;
animation.path = path;
animation.repeatCount = HUGE_VALF;
[imageView.layer addAnimation:animation forKey:@"theAnimation"];

最佳答案

对于任何感兴趣的人,我解决了我的问题。只需使用 NSTimer,检查并更新 UIImageViewframe 来自 presentation layer 通过:

CGRect viewLocation = [[[imageView layer] presentationLayer] frame];    
imageView.frame = CGRectMake(viewLocation.origin.x, viewLocation.origin.y, viewLocation.size.width, viewLocation.size.height);

在那之后,无论我的 ImageView 在哪里,触摸都会起作用:-)

关于ios uiimageview 点击手势在动画期间不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12287267/

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