gpt4 book ai didi

ios - 需要应用 UIRotationGestureRecognizer 后跟 UILongPressGestureRecongnizer

转载 作者:行者123 更新时间:2023-12-01 20:15:19 29 4
gpt4 key购买 nike

申请 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 手势,它就不会为同一个手指触摸添加旋转手势。我必须离开那个手指触摸,当我尝试旋转它时,它会很好地工作。但我想允许用户在检测到长按手势后立即开始旋转。

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

最佳答案

您可能希望 View 同时响应多个手势识别器。

当您可以调用 longPressGestureRecognizer 的方法并设置 Bool 时,

didReceiveLongPress = YES;

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

我假设你想要,发生旋转 仅在 之后长按。或者你可以去掉 IF 大小写,直接返回 YES。

关于ios - 需要应用 UIRotationGestureRecognizer 后跟 UILongPressGestureRecongnizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36787393/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com