UISearchBar presented by UISearchController in table header view animates too far when active

后端 未结 15 1079
长情又很酷
长情又很酷 2020-11-29 01:28

I am using UISearchController to present a search bar inside the header view of a tableview:

...
self.searchController.hidesNavigationBarDuringPresentation =         


        
15条回答
  •  没有蜡笔的小新
    2020-11-29 01:49

    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)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!

提交回复
热议问题