gpt4 book ai didi

ios - 触摸已移动 :withEvent: and UIRotationgestureRecognizer don't work together

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

我正在尝试这两种方法来移动和旋转 UIView。这两种方法单独工作,但如果我旋转然后移动 UIView,它就会消失。

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {


CGRect rect = self.aView.frame;

UITouch *touch = [touches anyObject];

CGPoint pPoint = [touch previousLocationInView:self.view];
CGPoint cPoint = [touch locationInView:self.view];

float deltaX = cPoint.x - pPoint.x;
float deltaY = cPoint.y - pPoint.y;

rect.origin.x = rect.origin.x + deltaX;
rect.origin.y = rect.origin.y + deltaY;

self.aView.frame = rect;

}
- (void)rotate:(UIRotationGestureRecognizer *) recognizer {

CGFloat rotation = angle + recognizer.rotation;

NSLog(@"%f", angle * 180 / M_PI);

self.aView.transform = CGAffineTransformMakeRotation (rotation);

if (recognizer.state == UIGestureRecognizerStateEnded)
angle = rotation;

}

最佳答案

手势识别器优先于 touchMoved,因此很难在同一 View 中同时使用它们。

使用 UIPanGestureRecognizer 而不是 touchMoved 来处理拖动 UIView。然后,您可以通过实现 UIPanGestureRecognizer 和 UIRotationGestureRecognizer 相互协作

– gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

方法,在 UIGestureRecognizerDelegate 协议(protocol)中定义。

关于ios - 触摸已移动 :withEvent: and UIRotationgestureRecognizer don't work together,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9148792/

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