3

I have a uinavigationbar as part of a navigationcontroller that I need to be 70 pixels high. Pre-iOS11 there are various solutions and I implemented one.

During the iOS 11 beta, I tried various ways of using autolayout to size the titleView. According to the WWDC talk, it should recognize width+height constraints within the titleview and accommodate them. It does not appear to do so.

It looks like it conflicts with the built in UILayoutGuide

(
    "<NSLayoutConstraint:0x60000008c760 UILayoutGuide:0x6000001acbe0'TitleView(0x7fe600c0a710)'.height == 44   (active)>",
    "<NSLayoutConstraint:0x61400008c6c0 EasyRelease.CustomTitleView:0x7fe606008e70.top >= UILayoutGuide:0x6000001acbe0'TitleView(0x7fe600c0a710)'.top   (active)>",
    "<NSLayoutConstraint:0x61400008c800 EasyRelease.CustomTitleView:0x7fe606008e70.centerY == UILayoutGuide:0x6000001acbe0'TitleView(0x7fe600c0a710)'.centerY   (active)>",
    "<NSLayoutConstraint:0x61400008bbd0 EasyRelease.CustomTitleView:0x7fe606008e70.height == 70   (active)>"
)

What gives? Is this feature not implemented correctly in iOS11, or am I missing something? Are there any known workarounds for adjusting titleview+uinavigationbar height?

edit: The way my code works, is I have added width + height constraints to the titleView. Is there anything else I should do? From the WWDC presentation this looked sufficient.

michael
  • 2,332
  • 2
  • 21
  • 27
  • If you want assistance you will need to detail how your current code works. However, all bugs (especially in beta software) should be reported to Apple: https://bugreport.apple.com – Robotic Cat Sep 15 '17 at 00:29
  • I'm having this exact same issue. Did you figure this out? – Brian Bethke Oct 04 '17 at 14:51
  • No, I believe that it's a bug in iOS. I submitted a bug report and example project to Apple, they thanked me and I have not heard back since that. My solution was to not rely on the uinavigationcontroller's navigationbar and instead instantiate my own navigationbar in each viewcontroller, setting its frame manually. – michael Oct 09 '17 at 20:52

2 Answers2

2

Take a look at the answer's here: iOS 11 navigationItem.titleView Width Not Set

I had a similar problem and overriding "intrinsicContentSize" lead me to the fix.

alasker
  • 309
  • 5
  • 18
0

This could work, it put a view above the NavigationBar. You should note that your image should be 70 pixels height. 13 is a magic number for 70 pixels image, because it appears centered in the navigation bar.

-(void)updateNavBarBackground{
    [[self.navigationController.navigationBar viewWithTag:1] removeFromSuperview];
    UIImage * image = [ UIImage imageNamed:@"NavBarImage"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.center = CGPointMake(self.navigationController.navigationBar.frame.size.width  / 2,
                               self.navigationController.navigationBar.frame.size.height / 2 - 13);

    imageView.tag = 1;
    [self.navigationController.navigationBar addSubview : imageView];
}