[Unity] iOS status bar display

iOS system has a top status bar represents the time, wifi status, power, etc. information.
When some app developers need to show the status bar.
Unity provides a setting to display the status bar.
In particular the Resolution and Presentation Player Settings below
Status Bar Hidden defaults to true.
It is set to false and to select a form of the Status Bar (default, translucent, opaque)

设置好之后build,在模拟器上显示出来。

可以看见显示状态栏会覆盖了游戏的视图。
要怎么解决这个问题呢。
比较简单的办法是,直接把游戏UI和画面下调20points。简单粗暴。
但是如果你有几十个场景要怎么办呢。。。
有没有什么办法能把游戏的视图整体下调20points呢?
用ios status bar overlay unity做关键词找到了下面的issue
[IOS] STATUS BAR OVERLAPS WITH APP UIVIEW
显然,没有被解决。
很多Unity方面关于iOS状态栏覆盖的提问最好的回答都是【不要显示它】。
这不科学。。。。。。
在Unity生成iOS应用的过程中有两个步骤,第一个步骤,生成xcode project。第二个步骤,从xcode project编译打包成app。
既然生成了xcode的project,肯定有调整unity view的办法。
在Unity生成Xcode的Project中最主要的一个文件是UnityAppController.mm
里面处理了Unity的视图显示问题。所以只要在这个文件里修正一下View视图就可以了。
在UnityAooContrllor.mm里面有这么一句话。

 

 

1

_window         = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];

 

这个_window被声明为UIWindow
iOS应用里首先是要生成一个UIWindow,然后把UIView控制器的视图加到UIWindow。通常在一个应用中只会有一个UIWindow。
所以这个·window应该就是生成的应用要使用的UIWindow。

将原来的初始化代码用下面的代码代替。

 

 

1

_window         = [[UIWindow alloc] initWithFrame: CGRectMake ([UIScreen mainScreen].bounds.origin.x, [UIScreen mainScreen].bounds.origin.y + 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height -20)];

 

因为屏幕坐标轴的原点实在屏幕的左上方,所以y坐标是加了20points。
修改后再build下试试

完成!

参考:
iOS开发基础知识:UIWindow和UIViewController

发布了6 篇原创文章 · 获赞 43 · 访问量 57万+

Guess you like

Origin blog.csdn.net/hany3000/article/details/104019269