【发布时间】:2011-12-06 20:40:45
【问题描述】:
我一直试图理解为什么我的模态呈现的图像没有显示在透明状态栏的下方。 _window.rootViewController 是一个 UILayoutContainerView,它是作为 Storyboard 中定义的第一响应者视图的 Tab 视图的一部分。
当 presentViewController 消息发送到 rootViewController 时,我可以在调用堆栈中看到
UIWindowController 转换:fromViewController:toViewController:target:didEndSelector:
尽管 rootViewController 和 coverImageViewController 的 frame 都是 0,0,320,480,但我还是用 0,20,320,460 调用了我的 coverImageViewController 的 setFrame。 这意味着图像最终以模态方式显示在状态栏下方,压缩了 20 像素。
我怀疑 UILayoutContainerView 在过渡中会发生某种变化,但我不确定如何确认或停止它。
任何帮助将不胜感激。 谢谢。
这是来源:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Get the cover image (320x480) from the main bundle and put it in an image view.
UIImage *coverImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"CoverPage.png" ofType:nil]];
UIImageView *coverImageView = [[UIImageView alloc] initWithImage:coverImage];
// Instantiate and set up the coverImageViewController.
coverImageViewController = [[UIViewController alloc] init];
// Desperate attempts to make image display below the status bar.
[coverImageViewController setModalPresentationStyle:UIModalPresentationFullScreen];
[coverImageViewController wantsFullScreenLayout];
[_window.rootViewController wantsFullScreenLayout];
[coverImageViewController setView:coverImageView];
// Make the window visible. Without a visible window the modal view won't come up.
[_window makeKeyAndVisible];
// At this point I am sure that both the rootViewController and the coverImageViewController frames are 0,0,320,480
// Display the coverImageViewController modally.
[self.window.rootViewController presentViewController:coverImageViewController animated:NO completion:nil];
}
我制作了一个基于标签栏的测试故事板项目,我将相同的代码放入 appDelegate.m 的 didFinishLaunchingWithOptions 方法中。
同样的问题。
我用一个黑色透明状态栏和一个带有独特图案的 Default.png 图像启动应用程序,清楚地表明它显示在状态栏下方。
调用 didFinishLaunching presentViewController 后,可以清楚地看到相同的图案覆盖图像缩小了 20 个像素(我也通过 NSLog 输出确认了这一点)并显示在下方而不是状态栏下方。
希望任何人都知道为什么 presentViewController 会这样做,以及如何以非笨拙的方式阻止它。
再次感谢。 特奥
【问题讨论】:
标签: ios splash-screen storyboard ios5