【发布时间】:2009-11-23 09:40:27
【问题描述】:
编辑 2:当我在顶部没有状态栏的情况下启动应用程序时,一切都按计划运行。使用状态栏,我无法让视图按照我的意愿行事。看起来 UINavigationController 通过减去状态栏的 20 像素来不断调整内容视图的大小。我不知道。
我创建了一个简单的基于 UINavigationController 的应用程序。此导航控制器中的根视图是 UITableView。在某个时间,我想从底部滑入一个 80 像素高的视图。顶部的整个视图(由 UINavigationController 控制的视图)应调整大小并缩小 80 像素,以便为新的底部视图腾出空间。
这基本上是我用来重新定位视图的代码:
-(void)showTeaser {
float adHeight = 80;
[adView setFrame:CGRectMake(0.0,self.navigationController.view.bounds.size.height, 320.0, 80.0)];
[[[UIApplication sharedApplication] keyWindow] addSubview:adView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[adView setAlpha:1.0];
[adView setFrame:CGRectMake(0.0,self.navigationController.view.bounds.size.height-adHeight, 320.0, 80.0)];
[self.navigationController.view setFrame:CGRectMake(0.0,0.0, 320.0, self.navigationController.view.bounds.size.height-adHeight)];
[self.view setFrame:CGRectMake(0.0, 0, 320.0, self.view.bounds.size.height-adHeight)];
[UIView commitAnimations]; }
我降低了导航栏的 alpha,将 UITableviewController 的视图设置为红色。新视图为紫色。
这就是发生的事情。第一张截图初始状态。一切看起来都很正常。第二个屏幕截图显示了更改帧后的状态。 UITableviewController 的视图总是被推到导航栏下方 20 像素。此外,如果我尝试向 keywindow 添加更多视图,它们最终总是比我预期的高 20 像素。它几乎看起来像键窗口(减去导航栏)被推高了 20 像素。
编辑 1:无论我调整视图的大小,它始终是 20 像素。
向键窗口添加视图是否会出错?我不应该这样做吗?
alt text http://www.hans-schneider.de/iphone-seo/1.pngalt text http://www.hans-schneider.de/iphone-seo/2.png
【问题讨论】:
-
我已经使用了我的 tableviewcontrollers 视图的自动调整大小掩码,但这并没有改变基本问题。
标签: iphone objective-c