presentViewController and displaying navigation bar

后端 未结 12 477
自闭症患者
自闭症患者 2020-12-07 13:27

I have a view controller hierarchy and the top-most controller is displayed as a modal and would like to know how to display the navigation bar when using

\         


        
12条回答
  •  粉色の甜心
    2020-12-07 14:14

    All a [self.navigationController pushViewController:controller animated:YES]; does is animate a transition, and add it to the navigation controller stack, and some other cool navigation bar animation stuffs. If you don't care about the bar animation, then this code should work. The bar does appear on the new controller, and you get an interactive pop gesture!

    //Make Controller
    DetailViewController *controller = [[DetailViewController alloc] initWithNibName:nil                                                                                 
                                        bundle:[NSBundle mainBundle]];  
    //Customize presentation
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    controller.modalPresentationStyle = UIModalPresentationCurrentContext;
    
    //Present controller
    [self presentViewController:controller 
                       animated:YES 
                     completion:nil];
    //Add to navigation Controller
    [self navigationController].viewControllers = [[self navigationController].viewControllers arrayByAddingObject:controller];
    //You can't just [[self navigationController].viewControllers addObject:controller] because viewControllers are for some reason not a mutable array.
    

    Edit: Sorry, presentViewController will fill the full screen. You will need to make a custom transition, with CGAffineTransform.translation or something, animate the controller with the transition, then add it to the navigationController's viewControllers.

提交回复
热议问题