ipad - 获取 iPad 的当前方向?

标签 ipad orientation

在给定的事件处理程序(不是“shouldAutorotateToInterfaceOrientation”方法)中,如何检测当前的 iPad 方向?我有一个文本字段,我必须在横向 View 中设置动画(当键盘出现时),但不能在纵向 View 中设置动画,并且想知道我处于哪个方向以查看是否需要动画。

最佳答案

方向信息不是很一致,有多种方法。如果在 View Controller 中,您可以使用 interfaceOrientation 属性。从其他地方您可以调用:

[[UIDevice currentDevice] orientation]

或者,您可以请求接收方向更改通知:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

有些人还喜欢检查状态栏方向:

[UIApplication sharedApplication].statusBarOrientation

关于ipad - 获取 iPad 的当前方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2738734/

相关文章:

iPad(仅限 3G 机型)Safari 崩溃

video - FFMPEG - 使用方向元数据进行移动录制

xamarin - Xamarin.Forms UWP-如何将应用程序锁定为横向

android - 方向改变和Android VideoPlayer?到底是怎么回事?

ios - IOS7状态栏和导航栏问题

iphone - 如何渲染内存中 UIViewController 的 View 景观?

ios - Unity VR LandscapeLeft 在 iOS 中不起作用

ios - OverCurrentContext 防止方向改变

iphone - AudioPlaybackComplete使用未声明的标识符自调用方法

c# - 带 iPad 的 MVC.NET 2