Adjust SearchBar size in Navigation Bar when Orientation changes to Landscape iOS7

StackOverflow https://stackoverflow.com/questions/23547110

  •  18-07-2023
  •  | 
  •  

I'm using a Storyboard where I have a UIViewController embedded in a Navigation Controller. I have placed a SearchBar into the Navigation Controller "replacing" the TextView item with it. It works as expected in portrait.

The problem is when I rotate it to Landscape, where the Searchbar remains in the center and its height seems to be bigger than the Nav Bar.

I have tried configuring the constraints, but it hasn't been successful.

Could you help me please?

有帮助吗?

解决方案 2

I fixed it adding the search bar in the title view, this way:

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[self.searchBar setPlaceholder:@"Buscar Recetas"];
[self.searchBar sizeToFit];
[self.searchBar setDelegate:self];


[self.navigationItem setTitleView:self.searchBar];

Note that I'm not using a search display controller in this case. Search Display Controller already has a property where you can set the search bar in the navigation bar, like this:

self.searchdisplaycontroller.displaysSearchBarInNavigationBar = YES;

其他提示

Set Constraints to your Search bar.. It will shows the magic.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top