Search code examples
iosobjective-ciphoneuiviewcontrolleruitoolbar

Action bar in all uiviewcontrollers in iOs


What's the best approach of creating an action bar (only once) in iOs that persists its position/size/content in all the UIViewControllers? Can I animate the UIViewController being pushed without animating the bar?

I was checking if it can be done with the UIToolBar or the UINavigationController. Am I on the right track?

Thanks in advance


Solution

  • I ended up doing the following:

    1- Created a UIViewController in the story board that contains a UIView designed as an action bar and below it a container

    2- I embedded this container to another UIViewController that will be the root view controller in this case

    3- On prepareForSegue, I saved the UIViewController instance loaded inside the container

    4- To switch between this UIViewController and the second one:

    UIViewController *newController = ...
    UIViewController *oldController = ...
    
    [oldController willMoveToParentViewController:nil];
    [self addChildViewController:newController]; 
    
    [self transitionFromViewController:oldController 
    toViewController:newController 
    duration:0.1
    options:UIViewAnimationOptionTransitionNone
    animations:^(void) {
        oldController.view.frame = CGRectMake(0 - width, 0, width, height);
        newController.view.frame = CGRectMake(0, 0, width, height);
    } 
    completion:^(BOOL finished){
        [newController didMoveToParentViewController:self];
    }
    
    ];