2014-03-04 51 views
0

我有DrawingView並在其上偵聽UIPanGestureRecognizer,UIRotationGestureRecognizer和UIPinchGestureRecognizer。當PinchGesture處於活動狀態時,RotationGesture不會調用

- (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,我該怎麼辦?

感謝很多

+0

僅供參考,您的NSCH在您的捏識別器方法是「返回」後,所以它不會打印出來。 –

回答

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

我添加了功能到我的ViewControler.m並添加到ViewControler.h但問題沒有解決 – user3076539

+0

你需要設置你的手勢的委託爲「自我」。在上面的編輯中添加。 –

0

使用requireGestureRecognizerToFail:識別手勢如果其他手勢識別器做不執行。

[rotateRecognizer requireGestureRecognizerToFail: pinchRecognizer]; 
相關問題