SearchDisplayController SearchBar overlaps navigation bar and resizes iOS7

My application has a table controller, which is presented as a form sheet.

There is a UView at the top of the tableviewcontoller, and inside this UIView there is a navigation bar and a search bar.

Everything works fine with the older version of iOS, but in iOS7, when the user picks up the search bar, everything is messy.

Normal: enter image description here

When the user starts typing: enter image description here

After the ends: enter image description here

in.h

UITableViewController<UITextFieldDelegate,UISearchDisplayDelegate,UISearchBarDelegate> @property (nonatomic,weak) IBOutlet UINavigationBar *topBar; 

Tried a few things, but the code doesn't seem to change anything when a breakpoint is set, which it introduces to delegate methods, although

in.m

 //-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { // if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { // CGRect statusBarFrame = self.topBar.frame; // [UIView animateWithDuration:0.25 animations:^{ // for (UIView *subview in self.tableView.subviews) // subview.transform = CGAffineTransformMakeTranslation(0, statusBarFrame.size.height+50); // }]; // } //} // //-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller { // if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { // [UIView animateWithDuration:0.25 animations:^{ // for (UIView *subview in self.tableView.subviews) // subview.transform = CGAffineTransformIdentity; // }]; // } //} - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { CGRect frame = self.searchDisplayController.searchBar.frame; frame.origin.y += self.topBar.frame.size.height; self.searchDisplayController.searchBar.frame = frame; } } - (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { CGRect statusBarFrame = self.topBar.frame; CGRect frame = self.searchDisplayController.searchBar.frame; frame.origin.y -= statusBarFrame.size.height; self.searchDisplayController.searchBar.frame= frame; } } #Additional Info - (void)viewDidLoad { [super viewDidLoad]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { //self.searchDisplayController.searchBar.searchBarStyle= UISearchBarStyleProminent; self.edgesForExtendedLayout = UIRectEdgeNone; //self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight; } } 

enter image description here

In accordance with the point and the size of the breakpoint right attitude and frame sizes, but they do not change self.searchDisplayController.searchBar.frame at all

I also tried

 -(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { [self.topBar setHidden:YES]; } } -(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { [self.searchDisplayController.searchBar removeFromSuperview]; CGRect frame = self.searchDisplayController.searchBar.frame; frame.origin.y += self.topBar.frame.size.height; self.searchDisplayController.searchBar.frame = frame; [self.topView addSubview:self.searchDisplayController.searchBar]; [self.topView bringSubviewToFront:self.topBar]; [self.topBar setHidden:NO]; } } 

How can I solve this problem?

+6
source share
2 answers

try setting this value in the table view controller:

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)]){ self.edgesForExtendedLayout = UIRectEdgeNone; } 

And change the view hierarchy to have a view, and a tableView, a search bar, and a nag bar when it falls under surveillance. Make the table view controller a view controller and make it both a data source and a delegate.

Or don't use searchBarDisplayController and just use the search bar with its delegation methods:

 - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
+2
source

I had a similar problem, I think searchDisplayController extends the SearchBar size to the full size of tableHeaderView (I really don't know why it does this). I had a search bar and one custom toolbar (44 pixels high) in tableHeaderView.

I tricked him:

 - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { self.tableView.tableHeaderView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 44); } - (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller { self.tableView.tableHeaderView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 88); } 

So I just set tableHeaderView to the size of a single UISearchBar when I enter a search, and set it when all animations complete. This solved my problem. Even the animations still work (but they are not in the childViewController. I don't know why)

+2
source

Source: https://habr.com/ru/post/957528/


All Articles