【问题标题】:Unexpected resizing of a UIImageView presented modally using presentViewController使用 presentViewController 以模态方式呈现的 UIImageView 的意外大小调整
【发布时间】: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 会这样做,以及如何以非笨拙的方式阻止它。

再次感谢。 特奥

测试项目链接: http://dl.dropbox.com/u/1792284/ModalSplashTest.zip

【问题讨论】:

    标签: ios splash-screen storyboard ios5


    【解决方案1】:

    试试这个,在模态呈现后添加图像...

    【讨论】:

    • 不幸移动 [coverImageViewController setView:coverImageView];在 presentViewController 调用下面没有区别。很奇怪,真的。我根本没想到它会起作用。
    • 嗯,有时它有效。因为只有当你制作 presentViewController 时, viewDidLoad 才真正完成。如果您在此之前设置图像,可能会发生奇怪的事情。
    【解决方案2】:

    我决定今天早上再看一次,并决定让这项工作最简单(如果有点笨拙)的方法是在调用 presentViewController 之前 setStatusBarHidden:YES 并在它之后的行上设置 :NO 。 这具有在半透明状态栏下方显示模态视图的效果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多