سؤال

In my app, I have a nav bar and two toolbars visible in the main View Controller. I then have a container view in that main VC that fills the screen, behind the UI elements. I embedded a UIPageViewController in the container. I then set up a UICollectionViewController scene that is reused when swiping between the pages. This is done in code - see below. Basically, it presents the UICollectionViewController on screen.

It's working well, except when it appears on screen it covers up the UI of the main VC. I could change the height to reveal the UI, but I do want it to take up the entire screen. I just want it to lie behind the toolbars. That way when the user scrolls the Collection VC the content will be rendered underneath those translucent toolbars.

I understand why it's behaving the way it is, but I don't know how to fix it. I originally figured since it's all embedded in a Container it would respect the z-order of that container which appears fine in the storyboard, but I suppose if I'm just throwing the VC on screen in code I should expect such behavior. I'm just not sure how to get the desired behavior. Thanks for the assistance!

//the following code is in the main view controller

//set first page view controller
ContentCollectionViewController *startingViewController = [self viewControllerAtIndex:0]; //calls method below
[self.pageViewController setViewControllers:@[startingViewController]
                                  direction:UIPageViewControllerNavigationDirectionForward
                                   animated:NO
                                 completion:nil];

//move page view controller down to reveal the underlying UI and show my issue
self.pageViewController.view.frame = CGRectMake(0, 80, self.view.frame.size.width, self.view.frame.size.height);

//display created page VC
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
[self.view addSubview:self.pageViewController.view];

//in the viewControllerAtIndex method:
ContentCollectionViewController *contentCollectionViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ContentCollectionViewController"];
//set properties here...
return contentCollectionViewController;

enter image description here

enter image description here

هل كانت مفيدة؟

المحلول

I was finally able to solve it by changing

[self.view addSubview:self.pageViewController.view];

to

[self.view insertSubview:self.pageViewController.view atIndex:1];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top