3 回答

TA貢獻1853條經驗 獲得超9個贊
在IOS6中,您在三個地方都支持界面方向:
.plist(或“目標摘要”屏幕)
您的UIApplicationDelegate
正在顯示的UIViewController
如果遇到此錯誤,則很可能是因為您在UIPopover中加載的視圖僅支持縱向模式。這可能是由Game Center,iAd或您自己的視圖引起的。
如果是您自己的視圖,則可以通過重寫UIViewController上的supportedInterfaceOrientations來修復它:
- (NSUInteger) supportedInterfaceOrientations
{
//Because your app is only landscape, your view controller for the view in your
// popover needs to support only landscape
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
如果不是您自己的視圖(例如iPhone上的GameCenter),則需要確保.plist支持縱向模式。您還需要確保UIApplicationDelegate支持以縱向模式顯示的視圖。您可以通過編輯.plist,然后在UIApplicationDelegate上覆蓋supportedInterfaceOrientation來做到這一點:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

TA貢獻1780條經驗 獲得超5個贊
在另一種情況下,可能會出現此錯誤消息。我花了好幾個小時才找到問題。閱讀幾次后,此線程非常有幫助。
如果將主視圖控制器旋轉為橫向,并且您調用一個應以縱向顯示的自定義子視圖控制器,則在代碼如下所示時可能會發生此錯誤消息:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationPortrait;
}
這里的陷阱是xcode的intellisense建議“ UIInterfaceOrientationPortrait”,我對此并不在意。乍一看,這似乎是正確的。
右邊的面具叫
UIInterfaceOrientationMaskPortrait
請注意小前綴“ Mask”,否則您的子視圖將最終出現異常和上面提到的錯誤消息。
新的枚舉進行了位移。舊的枚舉返回無效值!
(在UIApplication.h中,您可以看到新的聲明:UIInterfaceOrientationMaskPortrait =(1 << UIInterfaceOrientationPortrait))
解決方案是:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
// ATTENTION! Only return orientation MASK values
// return UIInterfaceOrientationPortrait;
return UIInterfaceOrientationMaskPortrait;
}
快速使用
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}
- 3 回答
- 0 關注
- 1914 瀏覽
添加回答
舉報