施加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手势检测,它不加入旋转手势为同一手指触摸。 我必须要当我试图将其旋转将工作做好,并再次留下了手指触摸。 但我想,让用户尽快长按手势检测开始旋转。
任何帮助表示赞赏! 提前致谢!