gpt4 book ai didi

c - 在 UIViewController 中添加 View 时出现空白

转载 作者:太空宇宙 更新时间:2023-11-04 02:57:41 25 4
gpt4 key购买 nike

我刚刚遇到一个问题,当我向我的 UIViewController 添加一个新 View 时,顶部有一个小间隙。 (好像是状态栏的高度)

我使用 pushViewController 来显示这个 View ,如下所示:

MapViewController *map = [[[MapViewController alloc] init] autorelease];
[self.navigationController pushViewController:map animated:YES];

在我的 MapViewController 中,我只是创建了一个与 View Controller 具有相同框架的 MKMapView

- (void)viewDidLoad
{
[super viewDidLoad];

self.view.backgroundColor = [UIColor redColor];

_mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
[self.view addSubview:_mapView];
}

但结果是这样的:

enter image description here

我不确定我是否还遗漏了什么......

最佳答案

试试这个:

_mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];

UIView 的框架位于父 View 的坐标系中。

另一方面,UIView 的边界位于 View 本身的坐标系中。

在这种情况下,self.view 的框架将考虑状态栏(因为它在屏幕上的位置)- 因此状态栏的大小在顶部偏移。

关于c - 在 UIViewController 中添加 View 时出现空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15521227/

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