gpt4 book ai didi

ios - UIView 背景大小问题

转载 作者:行者123 更新时间:2023-11-28 22:33:31 25 4
gpt4 key购买 nike

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

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

 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}}

结果显示 ImageView 实际上应该覆盖 self.view,并且在其自身和状态栏之间完全没有填充。

UIViewController 是UINavigationController 的 Root View Controller ,我已将导航栏设置为隐藏。我认为这可能是导致问题的原因,但是,在删除 UINavigationController 并将其替换为 UIViewController 之后,填充仍然存在。

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

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

enter image description here

[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];

最佳答案

在您的应用委托(delegate)中,在将 View Controller 设为 Root View Controller 之前,将 FullScreenLayout 设置为 YES:

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

或者你可以在viewDidLoad中设置

[self setWantsFullScreenLayout:YES];

关于 setWantsFullScreenLayout 的总结:当 View Controller 呈现其 View 时,它通常会缩小该 View ,使其框架不会与设备的状态栏重叠。将此属性设置为 YES 会导致 View Controller 调整其 View 的大小,以便它填满整个屏幕,包括状态栏下方的区域。 (当然,要做到这一点,承载 View Controller 的窗口本身的大小必须能够填满整个屏幕,包括状态栏下方的区域。)在具有半透明状态的情况下,通常会将此属性设置为 YES栏并希望您的 View 内容在该 View 后面可见。来自 here

希望这对您有所帮助。

关于ios - UIView 背景大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16759796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com