Adding a custom view to the UINavigationController

I have UINavigationControllerthat when an event is triggered, I need to UIViewdisplay only under NavigationBar, but not interfere with the current one ViewController. I will also need to be made UIViewpermanent, as the controllers will be unloaded / shifted.

 -----------------
|   Status Bar    |
 -----------------
|     Nav Bar     |
 -----------------
|   Custom View   |
 -----------------
|                 |
| View Controller |
|                 |
 -----------------

Currently I have installed CustomView (UIView):

- (id)initWithNavigationController:(UINavigationController *)navController {
    self.navController = navController;
    return [self init];
}

- (id)init
{
    CGRect viewFrame = self.navController.view.frame;

    return [self initWithFrame:CGRectMake(viewFrame.origin.x,
                                      self.navController.navigationBar.frame.origin.y + self.navController.navigationBar.frame.size.height,
                                      viewFrame.size.width,
                                      40.0)];
}

Is that so?

+5
source share
1 answer
- (id)initWithNavigationController:(UINavigationController *)navController {
    CGRect viewFrame = navController.view.frame;

    if (self = [super initWithFrame:CGRectMake(viewFrame.origin.x,
                                      navController.navigationBar.frame.origin.y + navController.navigationBar.frame.size.height,
                                      viewFrame.size.width,
                                      40.0)]){
       self.navController = navController;
      }
    return self;
   }

Then

CustomView* _myCustomView = [[CustomView alloc] initWithNavigationController:navigationController];
[navigationcontroller.view addSubview:_myCustomView];
0
source