我在我的导航栏的titleView中添加了一个搜索栏。
除了方向改变外,它看起来不错。无论出于何种原因,搜索栏都在改变位置。好像搜索栏突然弹出或者导航栏太大了。
有没有其他人遇到此问题并知道如何修复它?我正在使用故事板,并想知道是否有我缺少的设置或其他东西。这是我的代码:
-(void) viewDidAppear:(BOOL)animated
{
UIImage *addImage = [UIImage imageNamed:@"reveal-icon.png"];
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setFrame:CGRectMake(0, 0, addImage.size.width, addImage.size.height)];
[addButton setBackgroundImage:addImage forState:UIControlStateNormal];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:addButton];
[self.navigationItem setLeftBarButtonItem:barButtonItem];
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 260.0, 44.0)];
searchBarView.autoresizingMask = 0;
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:searchBarView.frame];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
searchBar.delegate = self;
[searchBarView addSubview:searchBar];
self.navigationItem.titleView = searchBar;
}