Programmatically get height of navigation bar

前端 未结 14 1035
猫巷女王i
猫巷女王i 2020-12-04 08:02

I know that the presence of the more view controller (navigation bar) pushes down the UIView by its height. I also know that this height = 44px. I have also discovered tha

相关标签:
14条回答
  • 2020-12-04 08:53

    The light bulb started to come on. Unfortunately, I have not discovered a uniform way to correct the problem, as described below.

    I believe that my whole problem centers on my autoresizingMasks. And the reason I have concluded that is the same symptoms exist, with or without a UIWebView. And that symptom is that everything is peachy for Portrait. For Landscape, the bottom-most UIButton pops down behind the TabBar.

    For example, on one UIView, I have, from top to bottom:

    UIView – both springs set (default case) and no struts

    UIScrollView - If I set the two springs, and clear everything else (like the UIView), then the UIButton intrudes on the object immediately above it. If I clear everything, then UIButton is OK, but the stuff at the very top hides behind the StatusBar Setting only the top strut, the UIButton pops down behind the Tab Bar.

    UILabel and UIImage next vertically – top strut set, flexible everywhere else

    Just to complete the picture for the few that have a UIWebView:

    UIWebView - Struts: top, left, right Springs: both

    UIButton – nothing set, i.e., flexible everywhere

    Although my light bulb is dim, there appears to be hope.

    0 讨论(0)
  • 2020-12-04 08:54

    If you want to get the navigationBar height only, it's simple:

    extension UIViewController{
       var navigationBarHeight: CGFloat {
           return self.navigationController?.navigationBar.frame.height ?? 0.0
       }
    }
    

    However, if you need the height of top notch of iPhone you don't need to get the navigationBar height and add to it the statusBar height, you can simply call safeAreaInsets that's why exist.

    self.view.safeAreaInsets.top
    
    0 讨论(0)
提交回复
热议问题