Non-fullscreen UINavigationController

后端 未结 4 1250
臣服心动
臣服心动 2021-02-20 12:25

Is it possible to use a UINavigationController in such a way that it doesn\'t use the full window?

I\'ve tried setting it\'s view\'s frame as well as adding it\'s view t

4条回答
  •  伪装坚强ぢ
    2021-02-20 12:47

    This is my first post ever, although I have been learning an enormous amount from this community. So I wanted to thank you all for this.

    My challenge, and the reason I'm posting here, was to take the answer to this question and refactor it for my needs, using iOS5 and storyboards. This solution probably won't work well for older implementations, but I thought I'd post it anyway.

    Here's what I ended up with, and it works well (iPad app). This is all set up on my default UIViewController, set as root in storyboard view.

    Hope this helps out!

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
    
    
        // Do any additional setup after loading the view, typically from a nib.
    
        /*vars: 
         rightSideView is the containing view - this is where the UINavigationController will sit, along with it's view stack
         myStoryboard is self-explanatory I think
         myViewController is identified as in storyboard as "accountView", to be pulled from the storyboard and used as the rootview
         */
    
    
        //Steps
    
        //Add subview to this controller's view (for positioning)
    
    
        UIView *rightSideView = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 500, 600)];
        rightSideView.clipsToBounds = YES;//this little baby makes sure that the damn navigation bar clips!!
    
        rightSideView.backgroundColor = [UIColor grayColor];//so I can see it
    
        //instantiate view controller for nav controller's root view
        UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
        UIViewController *myViewController = [myStoryboard instantiateViewControllerWithIdentifier:@"accountView"];
    
        //create NavController
        UINavigationController *myNavController = [[UINavigationController alloc]initWithRootViewController:myViewController];
    
        //Add navController as one of my child ViewControllers
    
        [self addChildViewController:myNavController];
    
        //Add NavController's view into my constrained view
        [rightSideView addSubview:myNavController.view];
    
        //Finally, add right side view as a subview of myself
        [self.view addSubview:rightSideView];
    
    
    
    }
    

提交回复
热议问题