需要应用UIRotationGestureRecognnizer,然后是UILongPressGestureRecongnizer

在一个视图上应用UILongPressGestureRecongnizer ,请查看以下代码以供参考。

 @interface ViewController () { UIRotationGestureRecognizer *rotationGestureRecognizer6; } - (void)viewDidLoad { //--------Added LongPress Gesture----------// UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; longPress.minimumPressDuration = 2.0; [view6 addGestureRecognizer:longPress]; rotationGestureRecognizer6 = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationWithGestureRecognizer:)]; } #pragma mark - UILongPressGesture Handler Method -(void)handleLongPress:(UILongPressGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded) { NSLog(@"UIGestureRecognizerStateEnded"); } else if (sender.state == UIGestureRecognizerStateBegan){ NSLog(@"UIGestureRecognizerStateBegan."); [view6 addGestureRecognizer:rotationGestureRecognizer6]; } } #pragma mark - UIRotationGesture Handler Method -(void)handleRotationWithGestureRecognizer:(UIRotationGestureRecognizer *)recognizer { UIView *view = [recognizer view]; [view setTransform:CGAffineTransformRotate([view transform], [recognizer rotation])]; } 

即使我曾尝试在UILongPressGestureRecongnizer其他状态(如UIGestureRecognizerStateRecognizedUIGestureRecognizerStateChangedUIGestureRecognizerStatePossible添加Rotation Gesture。 没有一个人为我工作。

我面临的问题是,一旦标志手势检测到,它不会为相同的手指触摸添加旋转手势。 当我试图旋转它时,我必须保持手指的触摸状态。 但是我想让用户在长按手势检测后立即开始旋转。

任何帮助表示赞赏! 提前致谢!

您可能希望视图一起响应多个手势识别器。

当你可以调用longPressGestureRecognizer的方法并设置一个Bool时,

 didReceiveLongPress = YES; - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ if(didReceiveLongPress) return YES; else return NO; } 

我假设你想旋转发生 longPress 之后 。 或者你可以删除IF的情况下,直接返回YES。