2011-11-17 91 views
2

我有一個滾動視圖,顯示圖像視圖。我正試圖在圖像視圖上處理UIRotationGestureRecognizer。我得到了旋轉事件,並在相同的地方應用了所需的變換。圖像在滾動視圖中正確旋轉。後來,當我做像變焦滾動視圖任何操作或平移圖像旋轉和位置去的折騰UIScrollView縮放問題與UIRotationGestureRecognizer

_mainView是也用於縮放

UIRotationGestureRecognizer *rotationGesture=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];  
[_mainView addGestureRecognizer:rotationGesture];  
[rotationGesture release]; 

-(void) rotationGesture:(UIRotationGestureRecognizer *) sender {  
    if(sender.state == UIGestureRecognizerStateBegan || 
     sender.state == UIGestureRecognizerStateChanged) 
    { 
     sender.view.transform = CGAffineTransformRotate(sender.view.transform, 
                  sender.rotation); 
     _currRotation = _currRotation + sender.rotation; 
     [sender setRotation:0]; 
    } 
} 

我會想的UIScrollView的子視圖瞭解什麼是在滾動視圖中處理旋轉的正確方法,並且即使在滾動視圖中的縮放事件之後,它仍然保持旋轉。

回答

0

在UIGestureRecognizerDelegate落實gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:方法,並返回要認識同時所有手勢。如果您仍然遇到問題,請查看UIImageView Gestures (Zoom, Rotate) Question的答案。

祝你好運!

編輯:你的評論有我猜測,問題是,你一次只能有一個轉換,並且滾動視圖應用縮放轉換,替換旋轉之一。您可以移除原始縮放識別器(請參閱this question),或者在滾動視圖中嵌套另一個UIView,然後將旋轉變換應用於該旋轉變換。我喜歡選項二,這似乎更容易。如果使用選項1,則使用CGAffineTransformConcat獨立應用縮放和旋轉轉換。

+0

謝謝,我已經添加了相同的內容。問題不在於手勢識別器。主要問題是旋轉一旦發生,如果我滾動或縮放旋轉就會發生折騰,並且圖像不再在滾動視圖中正確對齊 –