需要先应用UIRotationGestureRecognizer,然后再应用UILongPressGestureRecongnizer [英] Need to apply UIRotationGestureRecognizer followed by UILongPressGestureRecongnizer
本文介绍了需要先应用UIRotationGestureRecognizer,然后再应用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])];
}
甚至我也尝试过在UIGestureRecognizerStateRecognized
、UIGestureRecognizerStateChanged
、UIGestureRecognizerStatePossible
等其他UILongPressGestureRecongnizer
状态下添加旋转手势。没有一个对我起作用。
我面临的问题是,一旦LogPress手势检测到,它不会为相同的手指触摸添加旋转手势。我必须离开手指触摸,当我再次尝试旋转时,它会工作得很好。但我想让用户一检测到长按手势就开始旋转。
如有任何帮助,我们不胜感激! 提前感谢!
推荐答案
您可能希望视图一起响应多个手势识别器。
当您可以调用LongPressGestureRecognizer的方法并设置Bool时,
didReceiveLongPress = YES;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
if(didReceiveLongPress)
return YES;
else
return NO;
}
我假设您希望旋转仅在LongPress之后发生。或者,您可以删除IF大小写并直接返回YES。
这篇关于需要先应用UIRotationGestureRecognizer,然后再应用UILongPressGestureRecongnizer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文