UISearchBar在导航栏中移动位置

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

不知道为什么会发生这种情况,我的导航栏中有一个UISearchBar,但是当我开始滚动SearchResultsTableView时,搜索栏似乎跳了它的位置,我得到错误警告:[<CALayer: 0x16550840> display]: Ignoring bogus layer size

以下是搜索栏移位的屏幕截图。

它非常小但非常引人注目。有任何想法吗?谢谢!

这是我用来设置搜索栏的代码

if (!self.cardSearchDisplayController) {
    CGFloat searchBarHeight = 64.0;
    self.cardSearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, searchBarHeight)];
    self.cardSearchBar.delegate = self;
    self.cardSearchBar.showsCancelButton = YES;

    self.cardSearchDisplayController = [[UISearchDisplayController alloc]initWithSearchBar:self.cardSearchBar contentsController:self];
    self.cardSearchDisplayController.delegate = self;
    self.cardSearchDisplayController.searchResultsDataSource = self;
    self.cardSearchDisplayController.searchResultsDelegate = self;
    self.navigationItem.titleView = self.cardSearchDisplayController.searchBar;
    self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
}
ios uinavigationbar uisearchbar uisearchdisplaycontroller
1个回答
1
投票

对于ios 7,你必须使用这个,在viewDidLoad中为我修复它:

self.edgesForExtendedLayout = UIRectEdgeNone;

愿它能帮到你。

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