如何以编程方式确定 iPhone 界面方向? [英] How to programmatically determine iPhone interface orientation?
问题描述
UIDevice.orientation
的可能值包括 UIDeviceOrientationFaceUp
和 UIDeviceOrientationFaceDown
.虽然知道设备是扁平的可能很有用,但这并不能告诉我们它是扁平的,以纵向或横向模式显示界面.在设备返回模糊信息的情况下,有没有办法找到 GUI 的当前方向?我想我可以跟踪方向更改事件以记住最后的纵向/横向方向或检查主 UIView 的边界高度和宽度,但这似乎很麻烦.设备或 UIView 上是否有我遗漏的属性?
The possible values for UIDevice.orientation
include UIDeviceOrientationFaceUp
and UIDeviceOrientationFaceDown
. While it might be useful to know that the device is flat, this doesn't tell us whether it's flat displaying an interface oriented in portrait or landscape mode. Is there a way to find the current orientation of the GUI in cases where the device is returning ambiguous information? I suppose I could track orientation change events to remember the last portrait/landscape orientation or check the main UIView's bounds height and width, but that seems kludgey. Is there a property on the device or UIView that I'm missing?
推荐答案
在视图控制器中你可以简单地使用代码:
In a viewcontroller you can simply use the code:
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
UIInterfaceOrientation 是一个枚举:
The UIInterfaceOrientation is an enum:
typedef enum {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeRight
} UIInterfaceOrientation;
这篇关于如何以编程方式确定 iPhone 界面方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!