ios – 在应用程式额外资讯中检测方向的最佳方式是什么?

ios – 在应用程式额外资讯中检测方向的最佳方式是什么?,第1张

概述在应用程序扩展中检测设备方向的最佳方法是什么?我在这里找到的解决方案有不同的结果: How to detect Orientation Change in Custom Keyboard Extension in iOS 8? Get device current orientation (App Extension) 我看过大小类和UITraitCollection,发现设备不准确地报告说它实际 在应用程序扩展中检测设备方向的最佳方法是什么?我在这里找到的解决方案有不同的结果:

How to detect Orientation Change in Custom Keyboard Extension in iOS 8?

Get device current orientation (App Extension)

我看过大小类和uitraitcollection,发现设备不准确地报告说它实际上是横向的(不知道这是否是 *** 作系统的错误,或者我没有正确的方式来查询正确的API).

什么是最好的方法来完成:

>当第一次加载扩展时,设备的当前方向
>设备将旋转到的方向
>设备旋转到的方向

谢谢,

解决方法 我面对这个问题,也透过你的例子,但并没有很好的解决办法.
我如何解决它:我创建了一个类,可以对UIScreen值进行一些计算,并返回自定义的设备方向.

类标题:

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 – 在应用程式额外资讯中检测方向的最佳方式是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1110971.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存