How to create a static spy with a navigation controller?

I created a navigation controller with a stack of view managers.

I want to add a subview at the bottom, which remains static (doesn't move) while the user moves between this view stack.

As in some applications, the announcement panel is at the bottom.

How can i do this?

+3
source share
2 answers

If I understand correctly, this is what you want:

UIView below UINavigationController or below TabBar

You can do this by creating a custom UIViewController that includes a UINavigationController. Create a new class called "CustomViewController" and paste the following code:

Interface

#import <UIKit/UIKit.h>

@interface CustomViewController : UIViewController

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

@end

Implementation:

#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

Now for using CustomViewController:

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

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

, ( UIWindow). .

0

All Articles