簡體   English   中英

如何在 iOS 的狀態欄和導航欄頂部添加子視圖?

[英]How can I add a subview under statusbar and on top of Navigationbar in iOS?

我試圖在狀態欄和導航欄之間添加一個子視圖,所以我設置了 y position = 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.

我已經解決了這個問題。 現在,我沒有向下移動 keyWindow,而是向下移動了 rootviewController。

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

並添加了一個狀態欄子視圖以在頂部顯示一個假子視圖。 UiWindow 也需要是子類來檢測額外添加的視圖上的觸摸。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM