如何以编程方式确定iPhone界面方向? [英] How to programmatically determine iPhone interface orientation?

查看:88
本文介绍了如何以编程方式确定iPhone界面方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIDevice.orientation 可能的值包括 UIDeviceOrientationFaceUp UIDeviceOrientationFaceDown 。虽然知道设备是平的可能是有用的,但这并不告诉我们它是平面的,显示以纵向或横向模式定向的接口。在设备返回歧义信息的情况下,有没有办法找到GUI的当前方向?我想我可以跟踪定位的改变事件记得上次纵向/横向或检查的主要的UIView的边界高度和宽度,但似乎kludgey。 ?有没有我缺少的设备或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?

推荐答案

在一个的ViewController你可以简单地使用的代码:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆