不知道为什么会发生这种情况,我的导航栏中有一个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 7,你必须使用这个,在viewDidLoad中为我修复它:
self.edgesForExtendedLayout = UIRectEdgeNone;
愿它能帮到你。