2012-12-03 60 views
4

我的應用程序窗口的根視圖控制器是一個子類UINavigationController。我已經加入此代碼到類:preferredInterfaceOrientationForPresentation必須返回支持的接口方向(iOS 6)

- (BOOL)shouldAutorotate 
{ 
    return [self.topViewController shouldAutorotate]; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [self.topViewController preferredInterfaceOrientationForPresentation]; 
} 

以我根的UIViewController我已經加入此代碼:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; 
} 

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationPortrait; 
} 

當設備旋轉爲橫向此視圖控制器上,我提出模態的視圖控制器。當設備旋轉回縱向,我應該關閉該模式的看法,但是當我做我得到以下錯誤:

'preferredInterfaceOrientationForPresentation must return a supported interface orientation!' 

爲什麼會出現這個錯誤?


我試圖從shouldAutorotate根的UIViewController返回YES,現在我得到的錯誤「支撐取向與應用程序中沒有共同的方向,並shouldAutorotate將返回YES」。這對我來說沒有意義,因爲UIInterfaceOrientationPortrait是應用程序支持的方向之一。

回答

14

-supportedInterfaceOrientations中,您需要返回UIInterfaceOrientationMask而不是UIInterfaceOrientation的值。特別是,它看起來像你想UIInterfaceOrientationMaskPortrait

這裏是什麼-supportedInterfaceOrientations的文件說,對返回值:

Return Value

A bit mask specifying which orientations are supported. See 「UIInterfaceOrientationMask」 for valid bit-mask values. The value returned by this method must not be 0.