3

With IOS 11, I've encountered another one issue in UISearchController. As default height value became 56 rightBarButtonItem and leftBarButtonItem are staying in their old places, regardless of whether it's text or image.

I need to centre items to the search bar as it were in IOS 10.

refresh buttons are not centered

As you can see the item buttons are bit higher than center of searchbar.

I tried to do: [self.searchController.searchBar.heightAnchor constraintLessThanOrEqualToConstant: 44].active = YES;

But I got search bar overlapping buttons:

searchbar overlaps buttons

However, after I enter edit mode and return back by pressing Cancel - it begins to look good in case of 44 constraints.

I also tried to play with setting centerYanchor to imageView (of button) same as in searchBar but had crashed.

  • [self.searchController.searchBar.heightAnchor constraintEqualToConstant:44].active = YES; - is buggy on start and good alignment after in-out from editing mode. Still have no idea. – NeuroSMETANA Oct 01 '17 at 15:55
  • GIF: https://gyazo.com/1091697cd2759e4507740fef7eb0323a – NeuroSMETANA Oct 01 '17 at 16:15
  • I noticed from your video that the UISearchBar is shifting some pixel down when becomes first risponder. I have the same problem, I tried @canadaboy code but no success. Did that fix the shifting down for you? – aneuryzm Nov 01 '17 at 15:28

1 Answers1

2
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    if (@available(iOS 11.0, *)) {
        [self.searchBar.heightAnchor constraintLessThanOrEqualToConstant: 44].active = YES;
    }
}
canadaboy
  • 21
  • 3