2013-03-20 28 views
1

我剛碰到一個問題,當我向我的UIViewController添加新視圖時,頂部有一個小小的空白。 (看來是狀態欄的高度)在UIViewController中添加視圖時的空白間隙

我用pushViewController表明這個觀點,像這樣:

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

在我MapViewController我只是創造一個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

我不知道如果我仍然缺少的東西在這裏...

+0

請編輯標籤以包含正確的語言。你顯示的不是C. – tinman 2013-03-20 12:53:15

+0

@tinman對不起,我認爲Objective-C是C語言的一部分。 – 2013-03-22 09:35:43

回答

2

試試這個:

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

UIView的幀位於超視圖的座標系統中。

另一方面,UIView的邊界位於視圖本身的座標系統中。

在這種情況下,self.view框架將考慮狀態欄(因爲它是如何在屏幕上) - 因此狀態欄大小偏移在頂部。

+0

謝謝,這很有道理! – 2013-03-20 15:04:57

相關問題