2010-11-25 60 views
0

我在導航控制器中有一個子視圖,當iPad模擬器旋轉爲縱向或橫向時,主視圖是自動旋轉適合iPad的方向,但子視圖不是。子視圖也旋轉,但不適合ipad方向,子視圖方向總是朝着ipad主頁按鈕。如何在導航控制器中自動旋轉子視圖

我的問題是,如何使子視圖自動旋轉並具有像主視圖的方向?

有些身體可以幫助我,請...

回答

6

我已經解決了這個問題。

我使用NSNotification功能的子視圖的viewController類,在viewWillAppear中的方法,這是我實現:

[[NSNotificationCenter defaultCenter] 
addObserver:self 
selector:@selector(deviceRotated:) 
name:UIDeviceOrientationDidChangeNotification 
object:[UIDevice currentDevice]]; 

,然後,這是deviceRotated方法:

-(void)deviceRotated:(id)sender{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice]orientation]; 
    if (orientation == UIDeviceOrientationPortrait) { 
     CGAffineTransform rotate = CGAffineTransformMakeRotation (0.0); 
     CGAffineTransform translate = CGAffineTransformMakeTranslation(0, 30); 
     self.alertView.transform = CGAffineTransformConcat(translate, rotate); 

    } 
    else if (orientation == UIDeviceOrientationPortraitUpsideDown) { 
     CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 180/180.0f); 
     CGAffineTransform translate = CGAffineTransformMakeTranslation(-63, -100); 
     self.alertView.transform = CGAffineTransformConcat(translate, rotate); 

    }else if (orientation == UIDeviceOrientationLandscapeLeft) { 
     CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 90/180.0f); 
     CGAffineTransform translate = CGAffineTransformMakeTranslation(60, -180); 
     self.alertView.transform = CGAffineTransformConcat(translate, rotate); 


    }else if (orientation == UIDeviceOrientationLandscapeRight) { 
     CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 270/180.0f); 
     CGAffineTransform translate = CGAffineTransformMakeTranslation(-60, -140); 
     self.alertView.transform = CGAffineTransformConcat(translate, rotate); 

    } 
} 

最後,問題已經解決了。 this是幫助我的鏈接。

相關問題