我有drawingView并在其上监听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来调用,则不会调用UIRotationGestureRecognizer。
我的代码有什么问题?
我想我将使UISegmented选择模式,UIRotationGestureRecognizer或UIPinchGestureRecognizer,我该怎么办?
非常感谢
最佳答案
如果要一次识别多个手势,请尝试使用gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer
,例如:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
编辑:除了将委托包含在您的.h中之外,请确保将
UIGestureRecognizer
的委托设置为self,例如: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/