导航栏下方的UISearchBar,如何使其在活动时不向上推导航栏?

问题描述 投票:0回答:1

触摸我正在开发的苹果应用程序中的搜索栏会导致导航栏被隐藏。

这里有两张截图来演示:

screenshot of an apple phone screen, showing a blank app screen with 'Search' written on the navigation bar. A search box is displayed below this navigation bar

screenshot of an apple phone screen, showing an open search box, with cursor. There is a cancel button to the right of the search box, and a keyboard is displayed in the bottom half of the screen

当您点击搜索栏时,它会将导航栏向上推离屏幕顶部。如何让它在点击搜索时保持在原位?

谢谢!

uinavigationbar uisearchbar
1个回答
-1
投票

一种方法是阻止searchBar访问navigationBar - 实现

- (UINavigationController *)navigationController {
    return nil;
}

在分配为 UISearchBar 的委托(或 UISearchDisplayController 的委托)的 viewController 中。

如果您仍然需要在控制器的其他地方访问navigationController,请使用

super.navigationController

代替

self.navigationController
© www.soinside.com 2019 - 2024. All rights reserved.