简体   繁体   English

覆盖当前设备方向后,还剩下什么来标识设备的物理方向?

[英]After current device orientation been overwritten, what is left to identify physical orientation of the device?

In a tab based application, say the device is physically in landscape orientation and fixed in that orientation. 在基于标签的应用程序中,说设备在物理上处于横向,并固定在该方向。 One tab should only present in portrait, to force that orientation when user switching tab we do 一个标签只能以纵向显示,以在用户切换标签时强制该方向

[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];

After this, is there a way by which we can still find that device is physically landscape, so when user returning to landscape supported view, we can update "orientation" with right landscape value? 此后,有没有办法我们仍然可以发现设备在物理上是横向的,所以当用户返回横向支持的视图时,我们可以使用正确的横向值更新“方向”吗? because UIDevice->currentDevice->Orientation starts to report as Portrait since we updated that. 因为自我们更新以来,UIDevice-> currentDevice-> Orientation开始以纵向报告。 I couldn't find anything else that could tell the fact that device is physically in landscape orientation. 我找不到其他可以说明该设备实际上在横向方向上的事实。

Am i missing something? 我想念什么吗?

You can still get the rotation by using gyroscope I guess. 我猜你仍然可以通过使用陀螺仪来获得旋转。

But you should not be doing any of this. 但是您不应执行任何此类操作。 You need to use restriction per view controller (which I assume you tried but did not work). 您需要对每个视图控制器使用限制(我假设您尝试过但没有用)。 Once you have per view controller orientation locked ensure that message is forwarded correctly on embedded view controllers. 一旦每个视图控制器方向锁定,请确保在嵌入式视图控制器上正确转发消息。

That means that each UINavigationViewController should be overridden and return the settings of its top view controller. 这意味着应该重写每个UINavigationViewController并返回其顶视图控制器的设置。 It also means every UITabBarController should do the same using its currently shown view controller. 这也意味着每个UITabBarController应该使用其当前显示的视图控制器执行相同的操作。 And in real situations you may have a navigation controller holding a tab bar view controller showing another navigation controller having its currently visible view controller. 并且在实际情况下,您可能会拥有一个包含选项卡视图控制器的导航控制器,该选项卡显示了另一个具有当前可见的视图控制器的导航控制器。 And even in this case you must ensure that the bottom most navigation controller will receive settings from the top most visible view controller. 即使在这种情况下,您也必须确保最底部的导航控制器将从最顶部的可见视图控制器接收设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM