我在做搜索功能的時候,往往會把UISearchBar放到導(dǎo)航欄的titleView里,這樣會導(dǎo)致導(dǎo)航欄高度增加,像這樣:

image.png
這其實也沒啥影響,但是返回到上個頁面的時候,會導(dǎo)致self.view下移,如下:

image.png
解決辦法,就下面這句代碼就可以了
[[_searchBar.heightAnchor constraintEqualToConstant:44.0] setActive:YES];
我在做搜索功能的時候,往往會把UISearchBar放到導(dǎo)航欄的titleView里,這樣會導(dǎo)致導(dǎo)航欄高度增加,像這樣:
這其實也沒啥影響,但是返回到上個頁面的時候,會導(dǎo)致self.view下移,如下:
[[_searchBar.heightAnchor constraintEqualToConstant:44.0] setActive:YES];