如何在状态栏下和 iOS 中的导航栏顶部添加子视图?

问题描述

我试图在状态栏和导航栏之间添加一个子视图,所以我设置了 y 位置 = 0,然后我减小了 UIApplication Keywindow 的大小,以便它可以释放顶部的空间。

但是状态栏看起来很奇怪并且它也被移动了。

enter image description here

导航栏向下移动,没关系。但我还需要显示正确的状态栏。 这是我的代码。

    float yPosition = 0;
    CGRect fr = CGRectMake(0,yPosition,UIScreen.mainScreen.bounds.size.width,40);
    
    runningCallView.frame = fr;
    
    [UIApplication sharedApplication].keyWindow.frame = CGRectMake(0,40,UIScreen.mainScreen.bounds.size.height-40);
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:runningCallView];```

Can anyone please help on this. Thank you.

解决方法

我已经解决了这个问题。 现在,我没有将 keyWindow 向下移动,而是将 rootviewController 向下移动。

[UIApplication sharedApplication].keyWindow.rootViewController.view.frame = CGRectMake(0,shiftDownwards,UIScreen.mainScreen.bounds.size.width,UIScreen.mainScreen.bounds.size.height-shiftDownwards);

并添加了一个状态栏子视图以在顶部显示一个假子视图。 此外,UiWindow 需要是子类来检测额外的 addedView 上的触摸。

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...