状态栏为横向,但[[UIApplication sharedApplication] statusBarOrientation]返回纵向 [英] Status bar is Landscape, but [[UIApplication sharedApplication] statusBarOrientation] returns portrait

查看:463
本文介绍了状态栏为横向,但[[UIApplication sharedApplication] statusBarOrientation]返回纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎是间歇性的,但我不确定为什么。在设备(iPad)上运行我的应用程序时,我有一些代码可以根据当前设备方向加载带有一些图像视图的滚动视图。即使设备在加载前是横向的,视图也会像纵向一样被加载。

This problem appears to be intermittent, but I am not sure why exactly. When running my application on the device (iPad), I have some code to load a scroll view with some image views according to the current device orientation. Even though the device is landscape before loading, the views are being loaded as if it were portrait.

通过调用 [[UIApplication]找到方向sharedApplication] statusBarOrientation]

视图设置为在旋转设备时调整其位置,实际上,旋转为纵向然后回到风景将它们返回到正确的风景位置。是否所有应用程序都以纵向方式开始,如果需要,很快就会更改为横向?我是否想过早检查方向(在要加载的第一个视图控制器的 init 期间)?

The views are set up to adjust their positions when the device is rotated, and indeed, rotating to portrait and then back to landscape returns them to the correct landscape positions. Is it the case that all applications start off in portrait and soon change to landscape if required? Am I trying to check the orientation too soon (during the init of the first view controller to be loaded)?

推荐答案

如果你是子类化UIWindow或状态栏,你会看到这个,因为这是ipad设备的原生方向。 UIWindow将方向和坐标转换为我们习惯的方式。 makeAndKeyVisible后,视图控制器中的设备和界面方向应该符合预期。你不会偶然使用MTStatusBarOverlay吗?我经历了同样的事情,它归结为实例化的顺序。

If you're subclassing UIWindow or the status bar you'll see this because that's the ipad device's native orientation. The UIWindow translates the orientation and coordinates into what we're used to. After you makeAndKeyVisible, your device and interface orientation in view controllers should be as expected. You wouldn't by chance be using MTStatusBarOverlay would you? I went through the same thing and it came down to the order of instatiation.

这篇关于状态栏为横向,但[[UIApplication sharedApplication] statusBarOrientation]返回纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆