【问题标题】:NavigationBar from UINavigationController not positioned correctlyUINavigationController 中的 NavigationBar 未正确定位
【发布时间】:2010-05-26 07:38:57
【问题描述】:

所以,我的 iPad 程序有一个伪拆分视图控制器(我实现的一个,而不是基础 SDK 控制器),并且不久前可以正常工作。它具有基本布局(主视图为 UINavController,右侧为细节视图控制器),但我有它,因此主视图在旋转到纵向视图时不会消失。

最近,我添加了一个 UITabBarController 来包含整个拆分视图,这使得导航栏变得不稳定,而所有其他视图的位置都很好。此外,只有当 iPad 处于横向或倒置纵向时程序启动时,导航栏才会出现位置错误。如果一开始是纵向的,一切都很好。

可在此处找到示例图像: http://profile.imageshack.us/user/Pzychotix

导航栏向上的图像是我最初启动程序时的图像。 导航栏向下的图像是我旋转一次或多次后的图像。

相关代码:

RootViewController.m:
- (void)loadView {
navController = [[NavigationBreadcrumbsController_Pad alloc] init];

ABTableViewController_Pad * tableViewController = [[ABTableViewController_Pad alloc] initWithNibName:@"ABTableView"];

master = [[UINavigationController_Pad alloc] initWithRootViewController:tableViewController];
[tableViewController release];

// Dummy blank UIViewcontroller
detail = [[UIViewController alloc] init];
detail.view = [[[UIView alloc] init] autorelease];
[detail.view setBackgroundColor:[UIColor grayColor]];

self.view = [[[UIView alloc] init] autorelease];
self.view.backgroundColor = [UIColor blackColor];
[self positionViews];
[self.view addSubview:navToolbarController.view];
[self.view addSubview:master.view];
[self.view addSubview:detail.view];
}


// Handles the respositioning of view into it's current orientation
-(void)positionViews{

CGFloat tabBarOffset = 0;

if(self.tabBarController){
    tabBarOffset = self.tabBarController.tabBar.frame.size.height;
}

if(self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    self.view.frame = CGRectMake(0, 0, 768, 1004);
    navController.view.frame = CGRectMake(0,0,768,44);
    //adjust master view
    [master.view setFrame:CGRectMake(0, 44, 320, 1024 - 44 - 20 - tabBarOffset)];

    //adjust detail view
    [detail.view setFrame:CGRectMake(321,44, 448, 1024 - 44 - 20 - tabBarOffset)];
}
// Landscape Layout
else{
    self.view.frame = CGRectMake(0, 0, 748, 1024);
    navToolbarController.view.frame = CGRectMake(0,0,1024,44);
    //adjust master view
    [master.view setFrame:CGRectMake(0, 44, 320, 768 - 44 - 20 - tabBarOffset)];

    //adjust detail view
    [detail.view setFrame:CGRectMake(321,44, 1024 - 320, 768 - 44 - 20 - tabBarOffset)];
}

}

【问题讨论】:

  • 怎么定位错了?
  • 我添加了新的示例图片。

标签: objective-c uinavigationcontroller uitabbarcontroller ipad


【解决方案1】:

好吧,我已经找到了解决方案,但我仍然在摸不着头脑,为什么它会起作用。

基本上,我在 UINavigationController 上调用了 layoutIfNeeded,这一切都解决了。我不明白为什么它以前可以工作,或者为什么我需要调用 layoutIfNeeded,因为我认为 setFrame 会自动处理控制器的任何子视图的布局。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    相关资源
    最近更新 更多