UISearchBar增加了iOS 11中的导航栏高度 [英] UISearchBar increases navigation bar height in iOS 11

查看:996
本文介绍了UISearchBar增加了iOS 11中的导航栏高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UISearchBar 是导航栏的一部分,如:

I have my UISearchBar being part of the navigation bar like:

 let searchBar = UISearchBar()
 //some more configuration to the search bar
 .....
 navigationItem.titleView = searchBar

更新到 iOS 11 我的应用程序中的搜索栏发生了一些奇怪的事情。在 iOS 10 之前我的导航栏看起来像:

After updating to iOS 11 something weird happened to the search bar in my app. On iOS 10 and prior I had my navigation bar looking like:

现在 iOS 11 我有:

正如您所看到的那样,两个搜索栏的舍入存在差异,这并不困扰我。问题是搜索栏会增加导航栏的高度。所以,当我去另一个控制器时,它看起来很奇怪:

As you can see there is difference in the rounding of the two search bars which does not bothers me. The problem is that the search bar increases the height of the navigation bar. So when I go to another controller it looks weird too:

事实上,奇怪的黑线的高度加上当前导航栏的高度等于第二张图片中显示的导航栏的高度...

In fact that weird black line's height plus the current navigation bar's height is equal to the height of navigation bar shown in the second picture ...

任何想法如何摆脱黑线并在所有视图控制器上保持一致的导航栏高度?

Any ideas how to get rid of the black line and having consistent navigation bar height across all view controllers ?

推荐答案

您可以将高度为44的约束添加到iOS 11的搜索栏。

You can add a constraint of height 44 to the search bar for iOS 11.

if #available(iOS 11.0, *) {
    searchBar.heightAnchor.constraint(equalToConstant: 44).isActive = true
}

// Objective-c

// Objective-c

   if (@available(iOS 11.0, *)) {
      [searchBar.heightAnchor constraintEqualToConstant:44].active = YES;
    }

这篇关于UISearchBar增加了iOS 11中的导航栏高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆