gpt4 book ai didi

ios - 如何通过 UIView 引用获取设备方向?

转载 作者:可可西里 更新时间:2023-11-01 04:10:16 26 4
gpt4 key购买 nike

我需要从 ViewController 获取设备方向。 我不能基于:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

因为它有时会返回方向未知(例如当设备放在 table 上时)。

我只需要知道我当前的 UIView 以什么方向显示(是左横向还是右横向)。当方向改变时,我不需要更新这个值,我只是想知道它,当我要求它时。只是一些引用 view.orientation ;)。有什么可以帮助我的吗?我已经阅读了 UIView 文档,找到了一些对 UIWindow 的引用,但没有任何帮助。

最佳答案

您也可以从 UIApplication 获取设备方向,您尝试过使用

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

关于ios - 如何通过 UIView 引用获取设备方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10333374/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com