3

ビューコントローラーのスタックを使用してナビゲーションコントローラーを作成しました。

ユーザーがこのビューのスタック間を移動している間、静的なままである(移動しない)サブビューを下部に追加したいと思います。

一部のアプリと同様に、下部に「広告バー」があります。

これどうやってするの?

4

2 に答える 2

13

私が正しく理解していれば、これはあなたが望むものです:

UINavigationControllerの下またはTabBarの下のUIView

これを行うには、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];
于 2012-05-03T16:09:23.940 に答える
0

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

于 2012-05-03T15:18:53.527 に答える