当PinchGesture处于活动状态时,RotationGesture不会调用

时间:2014-03-04 00:58:53

标签: ios

我有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只调用UIPinchGestureRecognizer,则不会调用UIRotationGestureRecognizer。 我的代码有什么问题? 我想我会做一个UISegmented选择模式,UIRotationGestureRecognizer或UIPinchGestureRecognizer,我该怎么办?

非常感谢

2 个答案:

答案 0 :(得分:1)

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

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

编辑:除了在.h中包含代理人外,请确保将UIGestureRecognizer的代理人设置为自己,例如:

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];

答案 1 :(得分:0)

如果其他手势识别器未执行,请使用requireGestureRecognizerToFail:识别手势。

[rotateRecognizer requireGestureRecognizerToFail: pinchRecognizer];