在给定的事件处理程序(不是“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/