TabBar 应用程序中子视图偏移 20 像素
我有一个选项卡栏应用程序,当我显示模式视图控制器时,内容屏幕向顶部和左侧偏移约 20 像素。它看起来像这样:
我从导航控制器的子视图控制器(详细视图)呈现此视图(主视图)的选项卡视图。
当我显示视图时,我隐藏了选项卡栏和导航栏,但状态栏保持可见。将视图调整为居中(通过 Interface Builder 的模拟界面元素 -> 查看模式:中心)并在控制器中调用“viewDidLoad”后更改视图的框架似乎不会改变它。
- (void)viewDidLoad {
// this still doesn't cause it to shift
self.view.frame = CGRectMake(0, 20, 320, 460);
}
如何调整才能正确显示内容区域?
我像这样启动子视图:
[detailController presentModalViewController:tvc animated:NO];
应用程序的视图控制器层次结构:
在应用程序委托中创建带有两个子导航控制器的选项卡视图,并将导航控制器添加到选项卡栏的视图控制器:
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:tab1ViewController,
tab2ViewController, nil];
[window addSubview:tabBarController.view];
选项卡的每个视图控制器都创建为导航控制器1 个视图控制器:
// MainViewController inherits from UIViewController
[MainViewController *viewController = [[MainViewController alloc] initWithNib..];
tab1ViewController.viewControllers = [NSArray arrayWithObject:viewController];
由于 tab1ViewController 上的某些操作,详细视图控制器通过“pushViewController”启动:
DetailController *detailController = [[DetailController alloc]
initWithNibName:@"DetailView"
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:detailController animated:YES];
[detailController release];
我试图从详细控制器启动问题控制器。
I have a tab bar application and when I display a modal view controller, the content screen is offset by about 20 pixels to the top and left. It looks like this:
I'm presenting this view from the child view controller (detail view) of navigation controller (main view) of the tabview.
When I show the view, I'm hiding the tab bar and navigation bar but status bar is kept visible. Adjusting the view to be centered (through Interface Builder's Simulated Interface Elements->View Mode : Center) and changing the view's frame after a call to 'viewDidLoad' in the controller doesn't seem to shift it.
- (void)viewDidLoad {
// this still doesn't cause it to shift
self.view.frame = CGRectMake(0, 20, 320, 460);
}
What's the way to adjust this so that the content area is shown correctly?
I launch the child view like this:
[detailController presentModalViewController:tvc animated:NO];
The app's view controller hierarchy:
Tab view with two child navigation controllers are created in the app delegate and the nav controllers added to the TabBar's view controllers:
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:tab1ViewController,
tab2ViewController, nil];
[window addSubview:tabBarController.view];
Each view controllers of the tab is created as a NavigationController with 1 view controller:
// MainViewController inherits from UIViewController
[MainViewController *viewController = [[MainViewController alloc] initWithNib..];
tab1ViewController.viewControllers = [NSArray arrayWithObject:viewController];
A detail view controller is launched with 'pushViewController' as a result of some action on tab1ViewController :
DetailController *detailController = [[DetailController alloc]
initWithNibName:@"DetailView"
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:detailController animated:YES];
[detailController release];
It's from the detailController that I'm trying to launch the problem controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有些事情需要立即检查:“viewDidLoad”实际上被调用了吗?
如果是这样,赋值后 self.view.frame 设置为什么?
在末尾放置一个 NSLog,打印出 x、y、宽度、高度,然后看看那里有什么。
另外,由于vc是模态的,所以会占据整个屏幕。
“在 iPhone 和 iPod touch 设备上,modalViewController 的视图始终全屏呈现。”
哈特哈,
麦克风
Some things to check right off: is "viewDidLoad" actually getting called?
If so, what is self.view.frame set to after the assignment?
Put an NSLog at the end that prints out the x, y, width, height, and see what's there.
Also, since the trouble vc is modal, it will occupy the entire screen.
"On iPhone and iPod touch devices, the view of modalViewController is always presented full screen."
HTH,
Mike