【问题标题】:How can I add a subview under statusbar and on top of Navigationbar in iOS?如何在 iOS 的状态栏和导航栏顶部添加子视图?
【发布时间】:2021-01-13 12:51:33
【问题描述】:

我正在尝试在状态栏和导航栏之间添加一个子视图,因此我设置了 y 位置 = 0,然后我减小了 UIApplication Keywindow 的大小,以便腾出顶部空间。

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

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

    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.width, UIScreen.mainScreen.bounds.size.height-40);
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:runningCallView];```

Can anyone please help on this. Thank you.

【问题讨论】:

    标签: ios objective-c navigationbar subview uiwindow


    【解决方案1】:

    我已经解决了这个问题。 现在我没有向下移动 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 2014-03-29
      • 2013-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多