iOS 11自定义titleView大小; autolayout似乎被忽略了

时间:2017-09-14 22:14:58

标签: ios uikit ios11

我有一个uinavigationbar作为导航控制器的一部分,我需要70像素高。 iOS11之前有各种解决方案,我实现了一个。

在iOS 11测试期间,我尝试了各种使用autolayout来调整titleView大小的方法。根据WWDC的讲话,它应该在标题视图中识别宽度+高度约束并容纳它们。它似乎没有这样做。

它看起来与内置的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)>"
)

是什么给出的?这个功能在iOS11中没有正确实现,还是我错过了什么?是否有任何已知的变通方法可以调整titleview + uinavigationbar height?

编辑:我的代码工作方式是,我已经为titleView添加了width + height约束。还有什么我应该做的吗?从WWDC演示文稿看起来足够了。

2 个答案:

答案 0 :(得分:2)

看一下这里的答案:iOS 11 navigationItem.titleView Width Not Set

我遇到了类似的问题并且覆盖了“intrinsicContentSize”引导我进行修复。

答案 1 :(得分:0)

这可行,它在NavigationBar上方放置了一个视图。 您应该注意,您的图像应该是70像素高。 13是70像素图像的幻数,因为它显示在导航栏的中心。

-(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];
}