iOS 11 UISearchBar:left + rightbarbuttonitem垂直中心问题
问题描述:
对于IOS 11,我在UISearchController
中遇到另一个问题。 由于默认身高值变成了56 rightBarButtonItem
和leftBarButtonItem
都停留在原来的位置,无论它是文字还是图片。iOS 11 UISearchBar:left + rightbarbuttonitem垂直中心问题
我需要到中心项目到搜索栏,因为它是在IOS 10
refresh buttons are not centered
正如你所看到的项目的按钮比搜索栏的中心位高。
我试图做的:[self.searchController.searchBar.heightAnchor constraintLessThanOrEqualToConstant: 44].active = YES;
但我得到的搜索栏重叠的按钮:
然而,当我进入编辑模式,按下取消返回回来 - 它开始好看在44个约束的情况下。
我也尝试玩centerYanchor
到imageView
(的按钮)相同的searchBar
但已经崩溃。
答
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
if (@available(iOS 11.0, *)) {
[self.searchBar.heightAnchor constraintLessThanOrEqualToConstant: 44].active = YES;
}
}
+0
谢谢,是的,这样更好!除非您旋转设备... – NeuroSMETANA
[self.searchController.searchBar.heightAnchor constraintEqualToConstant:44] .active = YES; - 从编辑模式进入后,在开始时有错误,并且对齐良好。仍然不知道。 – NeuroSMETANA
GIF:https://gyazo.com/1091697cd2759e4507740fef7eb0323a – NeuroSMETANA
我从你的视频中注意到,UISearchBar在成为第一个应答时正在向下移动一些像素。我有同样的问题,我试过@canadaboy代码但没有成功。这是否解决了你的下移? – aneuryzm