I am using UISearchController to present a search bar inside the header view of a tableview:
...
self.searchController.hidesNavigationBarDuringPresentation =
I ran to this problem just recently and none of the solutions worked for me. Maybe because my UI is more complex (My table view with search supports in contained in UITabController inside a UiNavigationController) anyway, none of the above worker. I could simply solve my problem by this very neat piece of code I found at: UISearchController Not Redisplaying Navigation Bar on Rotate
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
if (bar == searchController.searchBar) {
return UIBarPositionTopAttached;
}
else { // Handle other cases
return UIBarPositionAny;
}
}
One more thing to add: after setting all my controller's hierarchy to extend under opaque and top bars, my search bar started to appear hidden under navigation bar and would've appeared right just after a rotation might happened. that was a cue for me that there is some lay out error and some information abut my layout was not right. this delegate method helps my controller understand the situation about the otherwise nomad search bar!
for iOS 11 & swift 4, set the line bellow in the viewController resolved my issue (searchBar jump down):
self.edgesForExtendedLayout = .bottom
unchecking Adjust Scroll View Insets
and
checking Under Top Bars
Fixed my problem
I guess you set UISearchBar frame.original.y = 64
there are the code
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
searchBar.frame = CGRectMake(0, 0, 376, 44);
wash can help you
its very simple just do clipsToBounds = true of header view of table view in witch search bar is added.
countryTableView.tableHeaderView?.clipsToBounds = true
Old question but I was able to solve this issue by setting
self.extendedLayoutIncludesOpaqueBars = YES;
on my view controller. I think is issue is caused by having an opaque navigation bar but setting hidesNavigationBarDuringPresentation
to NO
on your search controller, causing the search bar to incorrectly position itself when focused.