2012-05-03 6 views
3

私はビューコントローラのスタックを持つナビゲーションコントローラを作成しました。ナビゲーションコントローラで静的サブビューを作成するにはどうすればいいですか?

私は、このビューのスタックの間をユーザーが移動している間、静的な(移動しない)ままのサブビューを追加したいと考えています。

アプリの中のように、下部に「広告バー」があります。

どうすればいいですか?

答えて

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

ありがとうございますああ!!!これはまさに私が望むものです –

+0

ああ,,,私は問題を実装している間、私は実装されたソースコードを取得することがありますか? D –

+0

@PangHoMingあなたのUINavigationControllerの設定方法についてもっと教えていただければ、私は追加のコード/情報を提供することができます。 –

0

この静的サブビューをナビゲーションコントローラビューと同じレベル(通常はUIWindow近くの水平)に追加しないでください。それを追加して一番上にしてください。

関連する問題