gpt4 book ai didi

ios - PinchGesture 事件时不调用 RotationGesture

转载 作者:行者123 更新时间:2023-11-29 03:11:58 25 4
gpt4 key购买 nike

我在上面有 drawingView 和 listen UIPanGestureRecognizer、UIRotationGestureRecognizer 和 UIPinchGestureRecognizer。

- (void)viewDidLoad
{
[super viewDidLoad];

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
[self.drawingView addGestureRecognizer:panRecognizer];

UIRotationGestureRecognizer *rotateRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateRecognizer:)];
[self.drawingView addGestureRecognizer:rotateRecognizer];

UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchRecognizer:)];
[self.drawingView addGestureRecognizer:pinchRecognizer];
[self.drawingView reloadData];
}

-(void) pinchRecognizer:(UIPinchGestureRecognizer*) recognizer {
return;
NSLog(@"Call scale");
}

- (void)rotateRecognizer:(UIRotationGestureRecognizer*)recognizer {
NSLog(@"Call rotaion");
}

如果我只选择 UIRotationGestureRecognizer 或 UIPinchGestureRecognizer 就完美了。但是,如果使用 UIRotationGestureRecognizer 和 UIPinchGestureRecognizer 仅调用 UIPinchGestureRecognizer,则不会调用 UIRotationGestureRecognizer。我的代码有什么问题?我想我会制作一个 UISegmented 来选择模式,UIRotationGestureRecognizer 或 UIPinchGestureRecognizer,我应该怎么做?

非常感谢

最佳答案

如果您想同时识别多个手势,请尝试使用 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer,例如:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

编辑:除了在您的 .h 中包含委托(delegate)之外,请确保将您的 UIGestureRecognizer 的委托(delegate)设置为自身,例如:

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
panRecognizer.delegate = self;
[self.drawingView addGestureRecognizer:panRecognizer];

UIRotationGestureRecognizer *rotateRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateRecognizer:)];
rotateRecognizer.delegate = self;
[self.drawingView addGestureRecognizer:rotateRecognizer];

关于ios - PinchGesture 事件时不调用 RotationGesture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22160816/

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