获取 iPad 的当前方向? [英] Get current orientation of iPad?

查看:26
本文介绍了获取 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屋!

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