开发者

SearchBar rotation problem

开发者 https://www.devze.com 2023-02-04 20:48 出处:网络
I am sorry for images but I don\'t know better way to explain my problem. This is view when I start application, all is fine.

I am sorry for images but I don't know better way to explain my problem. This is view when I start application, all is fine.

SearchBar rotation problem

This is when I rotate phone, search bar top part is now a little bit under navigation bar.

SearchBar rotation problem

I start search and cancel it.

SearchBar rotation problem

Now search bar is not covered with navigation bar, but navigation bar is smaller by height.

SearchBar rotation problem

And when I go bac to vertical view, navigation bar is still small and I have a black hole under it.

SearchBar rotation problem

And I can't find why this is happening, any help?

This is the code how I create and add search bar:

- (void) loadView
{
    [super loadView];

    sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,45)];
    sBar.delegate = self;
    sBar.placeholder = @"Search";       
    self.tableView.tableHeaderView = sBar;

    UISearchDisplayController *searchDC = [[UISearchDisplayController alloc] initWithSearchBar:sBar contentsController:self];

    self.searchDisplayController = searchDC;    

    searchDC.delegate = self;
    searchDC.searchResultsDataSource = self;
    searchDC.searchResultsDele开发者_如何转开发gate = self;

    [sBar release];
    [searchDC release]; 
}

I didn't change anything in rotation methods specifically for navigation or search bar.


Verify all your views frames in:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

And if they are not ok set the correct frame.


The simpliest solution is to add UISearchBar to UITableView header. In this case all staff will be handled out of the box.

Setting frame can cause problems with UISearchBar width while switching between views and rotating. I experienced this issue in tab based app. Yeah, the test case is not so easy to reproduce, but stil it's a bug.

0

精彩评论

暂无评论...
验证码 换一张
取 消