1

In Session 204 of the 2017 WWDC it was mentioned that you can now use Auto Layout in the UIViewController navigationItem.titleView.

I tried various different options including the mentioned intrinsicContentSIze, custom view with custom frame as well as a complete Auto Layout approach with fixed height.

No matter what I do, the navigation bar always shrinks down my views to 44 points.

Furthermore when using the AutoLayout only approach, I'm getting this constraint error:

14:03:41.049847+0800 dfgd[60535:11623968] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000092a70 UILayoutGuide:0x6000001b3160'TitleView(0x7f8beb6061c0)'.height == 44   (active)>",
    "<NSLayoutConstraint:0x600000092250 UIView:0x7f8beb602f50.height == 200   (active)>",
    "<NSLayoutConstraint:0x6000000920c0 V:[UIView:0x7f8beb602f50]-(10)-|   (active, names: '|':dfgd.CustomView:0x7f8beb602930 )>",
    "<NSLayoutConstraint:0x6000000925c0 UIView:0x7f8beb602f50.centerY == dfgd.CustomView:0x7f8beb602930.centerY   (active)>",
    "<NSLayoutConstraint:0x6040000938d0 dfgd.CustomView:0x7f8beb602930.top >= UILayoutGuide:0x6000001b3160'TitleView(0x7f8beb6061c0)'.top   (active)>",
    "<NSLayoutConstraint:0x604000094a50 dfgd.CustomView:0x7f8beb602930.bottom <= UILayoutGuide:0x6000001b3160'TitleView(0x7f8beb6061c0)'.bottom   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000092250 UIView:0x7f8beb602f50.height == 200   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

QUESTION:

Has anybody managed to make that work? How do you get custom navigation bar heights to adopt to your title views?

xxtesaxx
  • 6,175
  • 2
  • 31
  • 50
  • Probably `.bottom` & `.height` coliding. – Jack Nov 15 '17 at 06:15
  • I think you can check this link -- https://stackoverflow.com/questions/40751366/how-can-i-change-height-of-navigation-bar-swift-3 – Morshed Alam Nov 15 '17 at 06:16
  • @Jack the title view itself has no constraints to the "outside world". The only constraints are top, right, bottom and left to the child view and the child views width/heigth and center x/y. According to the Session 204 that should be sufficient since everything inside the view is constrained. The TitleView.height constraint is the problem but this is added by the system. As far as I understood it, the system should calculate the title views height and use it instead of constraining it to 44. I guess its just one of those things which gets announced on WWDC but never implemented... so sad... – xxtesaxx Nov 15 '17 at 08:20
  • @xxtesaxx , [this so question](https://stackoverflow.com/questions/46324704/how-to-use-auto-layout-in-a-uinavigationbar-custom-titleview) may help. – LShi Mar 03 '18 at 08:22

0 Answers0