在我的应用程序中,我尝试添加搜索功能。我有 TableView Controller 和自定义顶部栏 View ,我在其中显示 UISearchBar。问题是叠加 View 总是在顶部栏下方一点点,它增加了它们之间的差距:
在我的 TableView Controller .m 文件的 viewDidLoad 中:
[super viewDidLoad];
LSDropdownViewController *menuCtrl = (LSDropdownViewController *)[self parentViewController];
menuCtrl.topSearchBar.delegate = self;
[menuCtrl.topSearchBar setBackgroundColor:[UIColor clearColor]];
[menuCtrl.topSearchBar setBackgroundImage:[UIImage imageWithGradientColors]];
[menuCtrl.topSearchBar setTintColor:[UIColor whiteColor]];
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:menuCtrl.topSearchBar contentsController:self];
self.searchController.delegate = self;
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
有什么想法吗?
最佳答案
这是由于 iOS7+。因此,要摆脱它,您必须通过将 y 值偏移 20 像素来手动设置搜索栏框架,即 searchBar.frame = CGRectMake(0,20,width,height)。
关于ios - UISearchDisplayController overlay 和 bar 之间的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23660506/