获取iPad的当前定位? [英] Get current orientation of iPad?
问题描述
在给定的事件处理程序(不是shouldAutorotateToInterfaceOrientation方法)中,如何检测当前的iPad方向?我有一个文本字段,我必须在横向视图中设置动画(当键盘出现时),但不在纵向视图中,并且想知道我在哪个方向看动画是否必要。
In a given event handler (not the "shouldAutorotateToInterfaceOrientation" method) how do I detect the current iPad orientation? I have a text field I have to animate up (when keyboard appears) in the Landscape view, but not in the portrait view and want to know which orientation I'm in to see if the animation is necessary.
推荐答案
方向信息不是很一致,有几种方法。如果在视图控制器中,您可以使用 interfaceOrientation
属性。从其他地方你可以打电话:
Orientation information isn't very consistent, and there are several approaches. If in a view controller, you can use the interfaceOrientation
property. From other places you can call:
[[UIDevice currentDevice] orientation]
或者,您可以请求接收方向更改通知:
Alternatively, you can request to receive orientation change notifications:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
有些人还想检查状态栏的方向:
Some people also like to check the status bar orientation:
[UIApplication sharedApplication].statusBarOrientation
这篇关于获取iPad的当前定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!