From b1ebb7ef4c2da951a737b1693c4d2ef80ee9eaf9 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Fri, 16 Jan 2015 14:38:22 +0100 Subject: [PATCH] Fix #1993: search bar misplaced on ipad landscape --- Classes/ContactsViewController.m | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Classes/ContactsViewController.m b/Classes/ContactsViewController.m index 417838d6e..60f8541de 100644 --- a/Classes/ContactsViewController.m +++ b/Classes/ContactsViewController.m @@ -148,6 +148,16 @@ static UICompositeViewDescription *compositeDescription = nil; [super viewWillDisappear:animated]; } +- (void)relayoutTableView { + CGRect subViewFrame= self.view.frame; + // let the toolBar be visible + subViewFrame.origin.y += self.toolBar.frame.size.height; + subViewFrame.size.height -= self.toolBar.frame.size.height; + [UIView animateWithDuration:0.2 animations:^{ + self.tableView.frame = subViewFrame; + }]; +} + - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; @@ -166,19 +176,17 @@ static UICompositeViewDescription *compositeDescription = nil; [self.view addSubview:picker.view]; self.sysViewController = picker; + self.searchBar.hidden = TRUE; } else if( !use_system && !self.tableController ){ - CGRect subViewFrame= self.view.frame; - // let the toolBar be visible - subViewFrame.origin.y += self.toolBar.frame.size.height; - subViewFrame.size.height -= self.toolBar.frame.size.height; self.tableController = [[[ContactsTableViewController alloc] init] autorelease]; self.tableView = [[[UITableView alloc] init] autorelease]; self.tableController.view = self.tableView; - self.tableView.frame = subViewFrame; + + [self relayoutTableView]; self.tableView.dataSource = self.tableController; self.tableView.delegate = self.tableController; @@ -316,6 +324,15 @@ static UICompositeViewDescription *compositeDescription = nil; [searchBar resignFirstResponder]; } +#pragma mark - Rotation handling + +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; + // the searchbar overlaps the subview in most rotation cases, we have to re-layout the view manually: + [self relayoutTableView]; +} + + #pragma mark - ABPeoplePickerDelegate -(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker