UIView背景大小调整问题 [英] UIView background sizing issue

查看:142
本文介绍了UIView背景大小调整问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正常地将UIImageView添加到UIViewController的UIView中,图像视图的框架与 self.view 相同,以确保图像将覆盖整个视图。但是,状态栏和imageView之间有一个大约20px的填充,我似乎无法摆脱它。

I'm adding a UIImageView to the UIViewController's UIView as I would normally, with the frame of the image view being the same as self.view to make sure that the image will cover the whole view. However, there is a roughly 20px padding between the status bar and the imageView which I can't seem to get rid of.

我尝试过NSLogging不同的帧,并收到以下结果:

I've tried NSLogging the different frames, and receiving the following results:

 NSLog(@"ImageView => %@", NSStringFromCGRect([imageView frame]));
 NSLog(@"self.view => %@", NSStringFromCGRect(self.view.frame));
 NSLog(@"Screen Bounds => %@", NSStringFromCGRect([[UIScreen mainScreen] bounds]));
 NSLog(@"App window => %@", NSStringFromCGRect([[[[UIApplication sharedApplication] delegate] window] frame]));

[LaunchViewController.m: line 26] ImageView => {{0, 0}, {320, 548}} 
[LaunchViewController.m: line 27] self.view => {{0, 0}, {320, 548}} 
[LaunchViewController.m: line 28] Screen Bounds => {{0, 0}, {320, 568}}   
[LaunchViewController.m: line 29] App window => {{0, 0}, {320, 568}}

结果显示图片视图应该实际上是覆盖 self.view ,它本身和状态栏之间根本没有填充。

The results show that the image view should in fact be covering self.view with no padding at all between itself and the status bar.

UIViewController是UINavigationController的根视图控制器,我已将导航栏设置为隐藏。我想也许这可能导致问题,但是在删除UINavigationController并用UIViewController替换它之后,填充仍然存在。

The UIViewController is the root view controller of a UINavigationController, and I have set the navigation bar to be hidden. I thought that maybe this could be causing the issue however, after removing the UINavigationController and replacing it with just the UIViewController, the padding was still there.

有没有人得到任何建议删除填充/之前遇到过这个问题并有修复?

Has anybody got any advice for removing the padding / has experience this issue before and has a fix?

这是一个显示正在发生的事情的图像 - 绿色区域是UIView( self.view ),橙色区域是UIImageView。

Here is an image showing what's going on - the green area is the UIView (self.view), and the orange area is the UIImageView.

[self.navigationController setNavigationBarHidden:YES];
[self.view setBackgroundColor:[UIColor greenColor]];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
[imageView setImage:[UIImage imageNamed:@"Orange-568h@2x.png"]];
[self.view addSubview:imageView];


推荐答案

在您的app delegate中,将FullScreenLayout设置为YES你使它成为视图控制器的根视图控制器:

In your app delegate set the FullScreenLayout to YES just before you make it the view controller the root view controller:

ViewController *vc = [[ViewController alloc] init];
[vc setWantsFullScreenLayout:YES];
[[self window] setRootViewController:vc];

或者您可以在viewDidLoad中设置

or you can set it in viewDidLoad

[self setWantsFullScreenLayout:YES];

关于setWantsFullScreenLayout的摘要:
当视图控制器显示其视图时,它通常会收缩查看,以便其框架不与设备的状态栏重叠。将此属性设置为YES会导致视图控制器调整其视图大小,使其填满整个屏幕,包括状态栏下的区域。 (当然,为此,托管视图控制器的窗口本身必须调整大小以填充整个屏幕,包括状态栏下方的区域。)如果您具有半透明状态,通常会将此属性设置为YES栏,并希望您的视图内容在该视图后面可见。来自此处

A summary on setWantsFullScreenLayout: When a view controller presents its view, it normally shrinks that view so that its frame does not overlap the device’s status bar. Setting this property to YES causes the view controller to size its view so that it fills the entire screen, including the area under the status bar. (Of course, for this to happen, the window hosting the view controller must itself be sized to fill the entire screen, including the area underneath the status bar.) You would typically set this property to YES in cases where you have a translucent status bar and want your view’s content to be visible behind that view. From here

希望这会有所帮助。

这篇关于UIView背景大小调整问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆