大佬教程收集整理的这篇文章主要介绍了ios – 在应用程式额外资讯中检测方向的最佳方式是什么?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
How to detect Orientation Change in Custom Keyboard Extension in iOS 8?
Get device current orientation (App Extension)
我看过大小类和UITraitCollection,发现设备不准确地报告说它实际上是横向的(不知道这是否是操作系统的错误,或者我没有正确的方式来查询正确的API).
什么是最好的方法来完成:
>当第一次加载扩展时,设备的当前方向
>设备将旋转到的方向
>设备旋转到的方向
谢谢,
类标题:
typedef NS_ENUM(NSInteger,InterfaceOrientationTypE) { InterfaceOrientationTypePorTrait,InterfaceOrientationTypeLandscape }; @interfacE interfaceOrientation : NSObject + (InterfaceOrientationTypE)orientation; @end
执行:
@implementation InterfaceOrientation + (InterfaceOrientationTypE)orientation{ CGFloat scale = [UIScreen mainScreen].scale; CGSize nativeSize = [UIScreen mainScreen].currentMode.size; CGSize sizeInPoints = [UIScreen mainScreen].bounds.size; InterfaceOrientationType result; if(scale * sizeInPoints.width == nativeSize.width){ result = InterfaceOrientationTypePorTrait; }else{ result = InterfaceOrientationTypeLandscape; } return result; } @end
我把它放到viewWillLayoutSubviews或viewDidLayoutSubviews方法来捕获方向改变事件.
if([InterfaceOrientation orientation] == InterfaceOrientationTypePorTrait){ // porTrait }else{ // landscape }
如果您想要确定设备方向(左,右,上下颠倒),则此方法无法解决您的问题.它只是返回肖像或风景方向.
希望会帮助你.
以上是大佬教程为你收集整理的ios – 在应用程式额外资讯中检测方向的最佳方式是什么?全部内容,希望文章能够帮你解决ios – 在应用程式额外资讯中检测方向的最佳方式是什么?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。