2012-05-03 44 views

回答

13

如果我理解正確的話,這是你想要的東西:

UIView below UINavigationController or below TabBar

您就可以向該通過創建包圍UINavigationController的一個自定義的UIViewController。創建一個名爲 「CustomViewController」 新品類,並粘貼以下代碼:

接口

#import <UIKit/UIKit.h> 

@interface CustomViewController : UIViewController 

- (id)initWithViewController:(UIViewController*)viewController bottomView:(UIView*)bottomView; 

@end 

實現:

#import "CustomViewController.h" 

@implementation CustomViewController 

- (id)initWithViewController:(UIViewController*)viewController bottomView:(UIView*)bottomView 
{ 
    self = [super init]; 
    if (self) { 

     // Set up view size for navigationController; use full bounds minus 60pt at the bottom 
     CGRect navigationControllerFrame = self.view.bounds; 
     navigationControllerFrame.size.height -= 60; 
     viewController.view.frame = navigationControllerFrame; 

     // Set up view size for bottomView 
     CGRect bottomViewFrame = CGRectMake(0, self.view.bounds.size.height-60, self.view.bounds.size.width, 60); 
     bottomView.frame = bottomViewFrame; 

     // Enable autoresizing for both the navigationController and the bottomView 
     viewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     bottomView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; 

     // Add views as subviews to the current view 
     [self.view addSubview:viewController.view]; 
     [self.view addSubview:bottomView]; 
    } 
    return self; 
} 

@end 

現在使用CustomViewController:

UIView *myBottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)]; 
myBottomView.backgroundColor = [UIColor redColor]; 

CustomViewController *customViewController = [[CustomViewController alloc] initWithViewController:<yourNavigationController> bottomView:myView]; 
+0

謝謝y歐!這正是我想要的 –

+0

哦,,,我有問題,而實現它,我可以得到一個實施的源代碼?這將如此偉大:D –

+0

@PangHoMing如果你告訴我更多關於你如何設置你的UINavigationController的信息,我可以提供額外的代碼/信息。 –

0

爲什麼不在與導航控制器視圖相同的級別添加此靜態子視圖(通常是UIWindow附近的級別)。只需將它添加到最上面即可。

相關問題