我有一個應用程序,其中UITabBarController作爲具有兩個控制器的rootViewController。一個是空控制器,第二個是Picker控制器,從ABPeoplePickerNavigationController擴展。問題在於視圖在標籤欄後面,並且由於該視圖從底部切斷。我只是強調了區域的截圖:具有UITabBarController的ABPeoplePickerNavigationController無法在iOS8中正確顯示
任何幫助將高度讚賞。
我有一個應用程序,其中UITabBarController作爲具有兩個控制器的rootViewController。一個是空控制器,第二個是Picker控制器,從ABPeoplePickerNavigationController擴展。問題在於視圖在標籤欄後面,並且由於該視圖從底部切斷。我只是強調了區域的截圖:具有UITabBarController的ABPeoplePickerNavigationController無法在iOS8中正確顯示
任何幫助將高度讚賞。
正式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
是無法擴展狀態欄下的導航欄,如果你改變它的框架
在這兩種這種情況下,然而,你的應用程序可能會被拒絕,因爲你是明確禁止它的類的子類。
更好,「合法」的方式來增加它使用的容器視圖控制器
創建一個新的視圖控制器,添加一個容器視圖,然後添加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
主視圖正好與導航欄
的顏色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);
}
有點遲到了,但這裏是我對這個問題的回答,或者至少爲你提供一些額外的輸入來制定一個完整的解決方案。
對我來說,問題似乎是因爲UIPeoplePickerNavigationController
不是子類,或者至少不推薦由Apple使用,所以無論如何你都不能完全使用它。我的意思是UIPeoplePickerNavigationController
意味着作爲一個模式視圖,應提交全屏iOS和每隔視圖控制器的頂部。您不應該嘗試將其用作導航控制器堆棧上的推視控制器。
所以我的建議是相當直接的。您應該簡單地使用您的UITabBarController
作爲presentViewController:animated:completion:
方法的接收方。這將負責在選項卡頂部顯示模式。
您可以通過當前視圖控制器的tabBarController
屬性訪問UITabBarController
:
ABPeoplePickerNavigationController *peoplePickerController = [ABPeoplePickerNavigationController new];
[peoplePickerController setPeoplePickerDelegate:self];
[self.tabBarController presentViewController:peoplePickerController animated:YES completion:^{}]
注:我從記憶寫這篇因此可能會有一些方法命名錯誤。
我想,還有,但沒有奏效。 –
你有'viewDidAppear'嗎?在'viewWillAppear'中它不起作用。我在Xcode中試圖回答 – LombaX
這裏鏈接到一個測試項目之前:https://www.dropbox.com/s/47hswos0xznj2kk/testpicker.zip?dl=0 – LombaX