2010-12-01 31 views
2

我有一個包含一些文本框的視圖。我設置視圖的方向是這樣使用CGAffine旋轉視圖後的翻譯

(void)deviceRotated:(id)sender 
{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice]orientation]; 

    if (orientation == UIDeviceOrientationPortrait) 
    { 
     CGAffineTransform affine = CGAffineTransformMakeRotation (0.0); 
     [self.View setTransform:affine]; 
    } 

    if (orientation == UIDeviceOrientationPortraitUpsideDown) 
    { 
     CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 180/180.0f); 
     [self.View setTransform:affine]; 
    } 
    else if (orientation == UIDeviceOrientationLandscapeLeft) 
    { 
     CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 90/180.0f); 
     [self.View setTransform:affine]; 
    } 
    else if (orientation == UIDeviceOrientationLandscapeRight) 
    { 
     CGAffineTransform affine = CGAffineTransformMakeRotation (M_PI * 270/180.0f); 
     [self.View setTransform:affine]; 
    } 
} 

我的問題是我要作出這樣的觀點向上移動時,鍵盤會出現,因爲一些文本框是由鍵盤隱藏。我想我必須使用CGAffineTransformMakeTranslation,但我不知道如何使用它後,旋轉。

有人可以幫我解決這個問題嗎?

回答

7

我們可以使用CGAffineTransformConcat。下面是我爲解決這個問題

CGAffineTransform rotate = CGAffineTransformMakeRotation (0.0); 
CGAffineTransform translate = CGAffineTransformMakeTranslation(-5, -150); 
self.alertView.transform = CGAffineTransformConcat(translate, rotate); 

,但我還是不明白,爲什麼在縱向& &縱向顛倒方向平移必須使用不同的點x和y的代碼。這是一個在景觀也發生左& &景觀正確的方向

0

這裏是如何向右旋轉

CGAffineTransform translate = CGAffineTransformMakeRotation(M_PI/18); 
view.transform = CGAffineTransformConcat(view.transform, translate); 

的,向左旋轉:

CGAffineTransform translate = CGAffineTransformMakeRotation(-M_PI/18); 
view.transform = CGAffineTransformConcat(view.transform, translate); 
+0

謝謝.....克萊頓 – 2015-12-28 07:27:40