Ios 触摸移动:带事件:和UIRotationGestureRecognitor don';我们不能一起工作

Ios 触摸移动:带事件:和UIRotationGestureRecognitor don';我们不能一起工作,ios,uigesturerecognizer,uitouch,Ios,Uigesturerecognizer,Uitouch,我正在尝试这两种方法来移动和旋转UIView。这两种方法分别工作,但如果我旋转然后移动UIView,它将消失 - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGRect rect = self.aView.frame; UITouch *touch = [touches anyObject]; CGPoint pPoint = [touch previousLocationInView:self.v

我正在尝试这两种方法来移动和旋转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,因此很难在同一视图中同时使用它们

使用UIPangestureRecognitor而不是touchMoved来处理UIView的拖动。然后,通过实现

– gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

方法,该方法在UIgestureRecognitzerDelegate协议中定义。

感谢您的快速帮助。我会这样做的。