在 Info.plist 文件中设置时,颠倒方向不起作用
Upside down orientation doesn't work when set in Info.plist file
在我的 Info.plist 文件中,我将 Supported Interface orientations
设置为提供的 4 种可能性,包括 Portrait (top home button)
.
当我 运行 我的应用程序时,将设备倒置时没有任何反应。风景还可以。
如果在 .plist
文件中我 select 只有 Portrait (bottom home button)
那么只有正常的肖像有效(这是有道理的),然后证明 .plist
文件有效.
如果在我的 UIViewController
之一中,我像这样覆盖 supportedInterfaceOrientations
:
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.All.rawValue)
}
然后就可以了(只针对这个UIViewController
)。
所以,正如我在 Info.plist
中指定的那样,为什么我的应用程序 运行 无法颠倒纵向?如果忽略它,在文件中将其作为选项提供有什么意义?
来自the doc:
The easiest way to set an app’s app’s supported interface orientations is to edit the project’s Info.plist file. As in the case of the view controller, you define which of the four interface orientations are permitted. For more information, see Information Property List Key Reference.
If you restrict the app’s supported orientations, then those restrictions apply globally to all of the app’s view controllers, even when your app uses system view controllers. At any given time, the mask of the topmost view controller is logically ANDed with the app’s mask to determine what orientations are permitted. The result of this calculation must never be 0. If it is, the system throws a UIApplicationInvalidInterfaceOrientationException exception.
因此,应用程序和视图控制器都必须允许定向。
将此代码添加到控制器
- (NSUInteger) supportedInterfaceOrientations {
return [super supportedInterfaceOrientations] | UIInterfaceOrientationMaskPortraitUpsideDown;
}
在我的 Info.plist 文件中,我将 Supported Interface orientations
设置为提供的 4 种可能性,包括 Portrait (top home button)
.
当我 运行 我的应用程序时,将设备倒置时没有任何反应。风景还可以。
如果在 .plist
文件中我 select 只有 Portrait (bottom home button)
那么只有正常的肖像有效(这是有道理的),然后证明 .plist
文件有效.
如果在我的 UIViewController
之一中,我像这样覆盖 supportedInterfaceOrientations
:
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.All.rawValue)
}
然后就可以了(只针对这个UIViewController
)。
所以,正如我在 Info.plist
中指定的那样,为什么我的应用程序 运行 无法颠倒纵向?如果忽略它,在文件中将其作为选项提供有什么意义?
来自the doc:
The easiest way to set an app’s app’s supported interface orientations is to edit the project’s Info.plist file. As in the case of the view controller, you define which of the four interface orientations are permitted. For more information, see Information Property List Key Reference.
If you restrict the app’s supported orientations, then those restrictions apply globally to all of the app’s view controllers, even when your app uses system view controllers. At any given time, the mask of the topmost view controller is logically ANDed with the app’s mask to determine what orientations are permitted. The result of this calculation must never be 0. If it is, the system throws a UIApplicationInvalidInterfaceOrientationException exception.
因此,应用程序和视图控制器都必须允许定向。
将此代码添加到控制器
- (NSUInteger) supportedInterfaceOrientations {
return [super supportedInterfaceOrientations] | UIInterfaceOrientationMaskPortraitUpsideDown;
}