开发者

Unexpected resizing of a UIImageView presented modally using presentViewController

I have been trying to understand why my modally presented image is not being shown underlaid the transparent status bar. The _window.rootViewController is a UILayoutContainerView, part of the Tab view that is the first responder view defined in the Storyboard.

When the presentViewController message is sent to the rootViewController i can see in the call stack that

UIWindowController transition:fromViewController:toViewController:target:didEndSelector:

calls the setFrame of my coverImageViewController with 0,20,320,460 despite both the rootViewController and coverImageViewController having a frame of 0,0,320,480. This means the image ends up being displayed modally underneath the status bar, compressed by 20 pixels.

My suspicion is that the UILayoutContainerView somehow changes in the transition, but I'm not sure how confirm it nor how to stop it.

Any help would be appreciated. Thanks.

This is the source:

- (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];
}

I made a test tab-bar based Storyboard project where I put the same code in appDelegate.m's didFinishLaunchingWithOptions method.

It has the same problem.

I start the app up with a black transparent status bar and a distinctively patterned Default.png image that makes it clear that it is shown underneath the status bar.

Once the didFinishLaunching presentViewController is called it is clear to see that the same pattern cover image is shrunk by 20 pixels (I also confirm this with NSLog output) and shown below rather than beneath the status bar.

Hope anyone knows why presentViewController does this and how to stop it in a non bodgy way.

Thanks again. Teo

Link to test project: http://dl.dropbox.com/u/1792284/ModalSplashTest.zip


Try this, add the image after you have presented it modally...


I decided to have a look at it again this morning and decided the easiest (if slightly bogdgy) way to make this work is to setStatusBarHidden:YES before calling the presentViewController and :NO on the line after it. This has the effect of showing the modal view underneath the translucent status bar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜