UISearchBar在导航栏中移动位置

时间:2014-02-20 02:58:35

标签: ios uinavigationbar uisearchbar uisearchdisplaycontroller

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

以下是searchBar移位的截图。

enter image description here enter image description here

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

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

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;
}

1 个答案:

答案 0 :(得分:1)

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

self.edgesForExtendedLayout = UIRectEdgeNone;

愿它能帮到你。

相关问题