2015-01-05 24 views

回答

1

正式ABPeoplePickerNavigationController不支持子類:link here

Subclassing Notes 
The ABPeoplePickerNavigationController class does not support subclassing. 

然而,問題是,你的ABPeoplePickerNavigationController子類的觀點是標籤欄下方延伸。 可以,例如,在運行時以這種方式改變它的大小

- (void) viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    CGRect rect = self.view.bounds; 
    rect.size.height = rect.size.height - 40; 
    self.view.frame = rect; 
} 

注意,40只是一個例子,您應該計算你的標籤欄控制器的高度,因爲它可以爲其它屏幕尺寸發生變化,旋轉。或者,更好的是,您可以搜索底層的UITableView實例並設置contentInset屬性。

編輯 這似乎也與狀態欄的問題,因爲ABPeoplePickerNavigationController是無法擴展狀態欄下的導航欄,如果你改變它的框架

在這兩種這種情況下,然而,你的應用程序可能會被拒絕,因爲你是明確禁止它的類的子類。

更好,「合法」的方式來增加它使用的容器視圖控制器

This Example

創建一個新的視圖控制器,添加一個容器視圖,然後添加ABPeoplePickerNavigationController這樣:

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // create the ABPeoplePickerNavigationController instance 
    ABPeoplePickerNavigationController *controller = [[ABPeoplePickerNavigationController alloc] init]; 

    // add a new child view controller to self 
    [self addChildViewController:controller]; 

    // alert the child that it has been added to the father 
    [controller didMoveToParentViewController:self]; 

    // update the child view frame to fit into the containerView 
    controller.view.frame = self.containerView.bounds; 

    // translate autoresizing mask into constraints, this is not needed but I usually do because is more pratical 
    [controller.view setTranslatesAutoresizingMaskIntoConstraints:YES]; 

    // add the `ABPeoplePickerNavigationController` view to the container 
    [self.containerView addSubview:controller.view]; 

} 

即使在這樣ABPeoplePickerNavigationController與狀態欄的問題(它不會在它正確地延伸),所以我限制了容器視圖頂部佈局指南,改變了山坳或ContainerViewController主視圖正好與導航欄

+0

我想,還有,但沒有奏效。 –

+0

你有'viewDidAppear'嗎?在'viewWillAppear'中它不起作用。我在Xcode中試圖回答 – LombaX

+0

這裏鏈接到一個測試項目之前:https://www.dropbox.com/s/47hswos0xznj2kk/testpicker.zip?dl=0 – LombaX

1

的顏色viewWillAppear中

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    self.topViewController.extendedLayoutIncludesOpaqueBars = YES; 
} 

viewDidAppear

- (void)viewDidAppear:(BOOL)animated 
{ 
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; 
    CGRect tabBarFrame = self.tabBarController.tabBar.frame;   
    self.view.frame = CGRectMake(0, statusBarFrame.size.height, self.view.frame.size.width, CGRectGetMinY(tabBarFrame) - statusBarFrame.size.height); 
} 
0

有點遲到了,但這裏是我對這個問題的回答,或者至少爲你提供一些額外的輸入來制定一個完整的解決方案。

對我來說,問題似乎是因爲UIPeoplePickerNavigationController不是子類,或者至少不推薦由Apple使用,所以無論如何你都不能完全使用它。我的意思是UIPeoplePickerNavigationController意味着作爲一個模式視圖,應提交全屏iOS和每隔視圖控制器的頂部。您不應該嘗試將其用作導航控制器堆棧上的推視控制器。

所以我的建議是相當直接的。您應該簡單地使用您的UITabBarController作爲presentViewController:animated:completion:方法的接收方。這將負責在選項卡頂部顯示模式。

您可以通過當前視圖控制器的tabBarController屬性訪問UITabBarController

ABPeoplePickerNavigationController *peoplePickerController = [ABPeoplePickerNavigationController new]; 
[peoplePickerController setPeoplePickerDelegate:self]; 
[self.tabBarController presentViewController:peoplePickerController animated:YES completion:^{}] 

注:我從記憶寫這篇因此可能會有一些方法命名錯誤。

相關問題