应用于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
例如UIGestureRecognizerStateRecognized
, UIGestureRecognizerStateChanged
, UIGestureRecognizerStatePossible
. 没有一个对我有用。
我面临的问题是,一旦检测到 logpress 手势,它就不会为同一个手指触摸添加旋转手势。我必须要离开那个手指触摸,然后当我尝试旋转它时它会很好地工作。但我想允许用户在检测到长按手势后立即开始旋转。
任何帮助表示赞赏!提前致谢!