导航栏中的搜索栏titleView在方向更改时弹出UINavigationItem?

时间:2013-07-25 15:58:45

标签: ios ios6 uinavigationcontroller uinavigationbar uinavigationitem

我在我的导航栏的titleView中添加了一个搜索栏。 enter image description here

除了方向改变外,它看起来不错。无论出于何种原因,搜索栏都在改变位置。好像搜索栏突然弹出或者导航栏太大了。 enter image description here

有没有其他人遇到此问题并知道如何修复它?我正在使用故事板,并想知道是否有我缺少的设置或其他东西。这是我的代码:

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

0 个答案:

没有答案