UINavigationBar rotation and auto layout

前端 未结 1 1358
忘了有多久
忘了有多久 2021-01-14 02:57

With regards to designing your own view Controller by inserting a UINavigationBar into the scene, I have found many references to questions regarding how the frame height do

相关标签:
1条回答
  • 2021-01-14 03:52

    Just make a vertical spacing constraint between your button and the top layout guide. This can be done in IB by control dragging from the button to the bottom of the navigation bar. Very simple, no code necessary.

    After Edit: If you add a stand alone navigation bar, you do need some code (as far as I know) to get the behavior you get automatically with a navigation controller. The way I did this is to add a navigation bar, and give it constraints to the sides of the superview, a vertical constraint to the top layout guide, and a fixed height of 44 points. I made an IBOutlet to this constraint (called heightCon in the code below). The button has a centerX constraint and a vertical spacing constraint to the navigation bar.

    - (void)viewWillLayoutSubviews {
        self.heightCon.constant = (self.view.bounds.size.height > self.view.bounds.size.width)? 44 : 32;
    }
    
    0 讨论(0)
提交回复
热议问题