我正在向UIViewController的UIView添加UIImageView,因爲我通常會將圖像視圖的框架與self.view
相同,以確保圖像覆蓋整個視圖。然而,狀態欄和imageView之間有大約20px的填充,我似乎無法擺脫。UIView背景調整問題
我已經試過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}}
結果表明,圖像視圖其實應該覆蓋self.view
沒有填充本身和狀態欄之間的所有。
UIViewController是UINavigationController的根視圖控制器,我已將導航欄設置爲隱藏。我認爲,也許這可能會導致問題,但刪除UINavigationController並用UIViewController替換它後,填充仍然存在。
有沒有人有任何建議去除填充/有經驗之前這個問題,並有修復?
這裏是一個圖像顯示發生了什麼 - 綠色區域是UIView(self.view
),橙色區域是UIImageView。
[self.navigationController setNavigationBarHidden:YES];
[self.view setBackgroundColor:[UIColor greenColor]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
[imageView setImage:[UIImage imageNamed:@"[email protected]"]];
[self.view addSubview:imageView];
你在做viewDidLoad或viewDidAppear? – Bartu
-viewDidLoad - 在調用super之前。 –
嘗試將其移動到viewDidAppear,在viewDidLoad上,如果您使用的是xib,則視圖大小基於xib的視圖。 – Bartu