2012-11-05 67 views
4

我想更改UINavigationController中的UIViewController's視圖的高度,以便在底部顯示橫幅,以免遮擋任何內容。更改UINavigationController中的視圖高度

我認爲這將是很容易通過只改變視圖的框架在viewDidLoad,但沒有奏效:

CGRect frame = self.view.frame; 
self.view.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height - 49.0f); 

我也試圖發起UINavigationController後添加

[navigationController.view setAutoresizesSubviews:NO]; 

但它看起來還是一樣的。

我現在唯一能想到的選擇是在模擬UITabBarController內部使用UINavigationController,它將被橫幅遮住,但這對我來說似乎不必要的複雜。

有沒有什麼辦法可以在UINavigationController裏改變視圖控制器視圖的高度?

+0

你是否將UIViewController添加到UINavigationController? –

+1

我想從這個鏈接得到一些想法.. http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/iAd_Guide/BannerAdvertisements/BannerAdvertisements.html –

+0

看看你的看法的佈局約束。默認情況下,它們將填充導航控制器空間。無論導航控制器上的autoresizesubviews如何 –

回答

4

有沒有辦法從視圖控制器內更改視圖控制器的觀點,但你可以使用自定義的容器視圖控制器:

// Create container 
UIViewController* container = [[UIViewController alloc] init]; 

// Create your view controller 
UIViewController* myVc = [[MyViewController alloc] init]; 

// Add it as a child view controller 
[container addChildViewController:myVc]; 
[container.view addSubview:myVc.view]; 
myVc.view.autoresizingMask = UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleHeight; 
myVc.view.frame = CGRectMake(0, 0, container.view.bounds.size.width, container.view.bounds.size.height-200); 

// Add your banner 
UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"banner"]]; 
imgView.autoresizingMask = UIViewAutoresizingMaskFlexibleWidth| UIViewAutoresizingMaskFlexibleTopMargin; 
imgView.frame = CGRectMake(0, container.view.bounds.size.height-200, container.view.bounds.size.width, 200); 
[myVc.view addSubview:imgView]; 

現在您可以container視圖控制器添加到您的導航控制器,而不是你的。

+0

這可能工作,但不知道它需要 –

+0

這是更可定製壽(你可以把你自己的意見作爲橫幅),也是很好,如果你沒有訪問視圖控制器,就像一個表格視圖... – jjv360

+0

我可以同意這個 –

相關問題