Search bar gets cut off when using UISearchController with a UITabBarController inside a UINavigationController

你。 提交于 2019-12-10 15:59:33

问题


I have an application that has a UITabBarController in a UINavigationController. (The UITabBarController is not the "Initial View Controller" for the story board.)

In the initial UIViewController, I have a UISearchController which allows for content to be searched from a remote source.

This worked fine until I added the UITabBarController. Now, the search bar displays fine in the default state, but once you start typing inside of it, it gets pushed up past the top edge of the view.

I realize this probably has a lot to do with automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, and/or edgesForExtendedLayout, but in all my tweaking, I've been unable to find the magic combo to get the UISearchController to not push itself up past the top of the view.

Any ideas on how to make it work?

See these screengrabs from this example project:

Initial view:

Search text box becomes first responder:

After typing a word and hitting enter:


回答1:


I ran into this issue too, and here's a solution: setting definesPresentationContext = true on UITabBarController instead of the table view controller seems to fix it.

Apparently, you have to go all the way up until navigation controller in container hierarchy. Not the most obvious thing in the world if you ask me.




回答2:


Although definesPresentationContext worked for me previously, since iOS 10 at some point I had to disable Adjust Scroll View Insets on my search results view controller. More on my answer at UISearchBar gets cut off when using a UINavigationController inside a UITabBarController



来源:https://stackoverflow.com/questions/29979628/search-bar-gets-cut-off-when-using-uisearchcontroller-with-a-uitabbarcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!