使用presentViewController 以模态方式呈现的UIImageView 意外调整大小
我一直试图理解为什么我的模态呈现的图像没有显示在透明状态栏下方。 _window.rootViewController 是一个 UILayoutContainerView,是 Tab 视图的一部分,是 Storyboard 中定义的第一个响应者视图。
当presentViewController消息发送到rootViewController时,我可以在调用堆栈中看到
UIWindowController的transition:fromViewController:toViewController:target:didEndSelector:
用0,20,320,460调用我的coverImageViewController的setFrame,尽管rootViewController和coverImageViewController的框架都是0, 0,320,480。 这意味着图像最终以模态方式显示在状态栏下方,并压缩了 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];
}
我制作了一个基于测试选项卡栏的 Storyboard 项目,其中我将相同的代码放入 appDelegate.m 的 didFinishLaunchingWithOptions 方法中。
它也有同样的问题。
我使用黑色透明状态栏和图案独特的 Default.png 图像启动应用程序,该图像清楚地表明它显示在状态栏下方。
一旦 didFinishLaunching PresentViewController 被调用,就可以清楚地看到相同的图案封面图像缩小了 20 像素(我也通过 NSLog 输出确认了这一点)并显示在下面而不是状态栏下方。
希望有人知道为什么 PresentViewController 会这样做以及如何以非身体方式阻止它。
再次感谢。 Teo
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个,在模态呈现后添加图像......
Try this, add the image after you have presented it modally...
今天早上我决定再次查看它,并决定完成这项工作的最简单(如果有点麻烦)的方法是在调用presentViewController之前设置StatusBarHidden:YES,并在其后面的行上设置:NO。
这具有在半透明状态栏下方显示模式视图的效果。
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.