簡體   English   中英

iOS是否有可能觀察者更改navigationBar的高度?

[英]iOS is it possible observer changes navigationBar height?

我有兩個按鈕的viewController

按鈕1:

在導航欄調整提示大小時設置提示文本和注意事項-向其添加子視圖

按鈕2:

顯示下一個viewcontroller,並且在該viewcontroller上未設置提示文本。

導航欄會調整大小,但仍具有子視圖。

我可以手動刪除自定義視圖,但是我只想在導航欄調整為正常大小而沒有提示時才這樣做。

如您在下圖所示

在此處輸入圖片說明

導航欄調整大小,然后在自定義視圖上返回箭頭-在這里我想隱藏自定義視圖。

將此代碼放在MainViewController @implementation之后和@end之前的MainViewController.m中

- (void)viewDidLayoutSubviews{

    if ([self respondsToSelector:@selector(topLayoutGuide)]) // iOS 7 or above
    {
        CGFloat top = self.topLayoutGuide.length;
        if(self.webView.frame.origin.y == 0){
            // We only want to do this once, or if the view has somehow been "restored" by other code.
            self.webView.frame = CGRectMake(self.webView.frame.origin.x, self.webView.frame.origin.y + top, self.webView.frame.size.width, self.webView.frame.size.height - top);
        }
    }
}

暫無
暫無

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

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