如何处理UIDeviceOrientationFaceUp和UIDeviceOrientationFaceDown?
这是一个菜鸟问题。
我使用以下方法检测方向:
UIInterfaceOrientationorientation = [[UIDevice currentDevice]orientation];
一切都很好,我根据报告的方向重新定位我的文本字段和标签
if (orientation = = UIDeviceOrientationPortrait ||orientation == UIDeviceOrientationPortraitUpsideDown)
和 else{} 对于其他一切,
我最近才发现的问题是 UIDevice
报告 UIDeviceOrientationFaceUp
或 UIDeviceOrientationFaceDown
。我该如何处理这种情况?我如何知道 UIDeviceOrientationFaceUp
和 UIDeviceOrientationFaceDown
是在纵向还是横向中发生?我知道设备朝上或朝下,但我不知道是否应该将所有内容重新定位为纵向或横向。
谢谢你!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Apple 建议不要使用设备方向进行视图布局。相反,每个视图控制器都有一个 interfaceOrientation 属性,并且
UIApplication
有一个 statusBarOrientation 属性,这两个属性都会返回当前界面< /em> 方向,适合视图布局。要监视更改,有
UIViewController
方法,例如 willRotateToInterfaceOrientation:duration: 将被调用,并发出诸如 UIApplicationWillChangeStatusBarOrientationNotification 将在界面方向发生变化。Apple recommends against using device orientation for view layout. Instead, each view controller has an interfaceOrientation property, and
UIApplication
has a statusBarOrientation property, both of which will return the current interface orientation, which is suitable for view layout.To monitor for changes, there are
UIViewController
methods like willRotateToInterfaceOrientation:duration: that will be called and notifications such as UIApplicationWillChangeStatusBarOrientationNotification that will be posted when an interface orientation change occurs.有点晚了,希望对某人有所帮助。
对于 iOS 6.0 及更高版本:
1) 在视图设置期间设置此代码以接收旋转通知:
2) 设置此代码以在旋转后捕获通知:
A bit late, hopefully it would help some one.
For iOS 6.0 and later:
1) Set this code during your View Setup to receive rotation notification:
2) Set this code to catch the Notification after rotation:
我有同样的问题
此方法生成 7 种可能的设备位置状态的通知:
但我只需要前 4 个,这是我解决此问题的方法(包含代码):
如何处理 UIDeviceOrientation 来管理视图布局
I have the same problems with
This method generate notifications for 7 possible device positional states:
But I only need the first 4, well this is my approach to solve this problem (with code included):
How to handle UIDeviceOrientation for manage views layouts