1

Reproduce (bug only with iPhone devices <= 8, works ok with iPhone X* devices):

  1. Open search bar (by clicking search item on top bar) in portrait mode

@IBAction func onSearchBarItemClicked(_ sender: UIBarButtonItem) { present(searchController, animated: true, completion: nil) }

enter image description here

  1. Rotate device to landscape position

enter image description here

  1. Rotate back to portrait position

enter image description here

Now it's below status bar and it overlaps the content at the bottom

How can I fix it?

UISearchController:

searchController = UISearchController(searchResultsController: nil)
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.keyboardType = UIKeyboardType.asciiCapable
searchController.searchBar.delegate = self

Update

Sample Project: https://github.com/anonym24/SearchBarBelowStatusBar/

user924
  • 8,146
  • 7
  • 57
  • 139
  • I have tested your above code in simulator it seems to work fine, pre and post rotation. Can you share your complete source code? – Deepak Singh May 18 '19 at 17:00
  • I did it on iPhone 7 – Deepak Singh May 18 '19 at 17:04
  • @Deepak https://github.com/anonym24/SearchBarBelowStatusBar/ – user924 May 18 '19 at 17:38
  • @Deepak run this app, click search bar item, don't close search bar, rotate to landscape with "alt+left" and then again to portrait with "alt+right" – user924 May 18 '19 at 17:42
  • @Deepak did you test the sample project? – user924 May 18 '19 at 18:42
  • yes, I did. It's because of the navigationBar. Not able to resolve yet. You can refer to this https://stackoverflow.com/questions/46318022/uisearchbar-increases-navigation-bar-height-in-ios-11 [ Workaround:You can use default searchBarController for navigationItem: navigationItem.searchController = searchController ] – Deepak Singh May 19 '19 at 03:03
  • @Deepak they say with this workaround it puts the search bar below the navigation – user924 May 19 '19 at 10:01

0 Answers0