在我的应用中,我在主视图控制器中有一个导航栏和两个工具栏。然后我在主要VC中有一个容器视图,它填充UI元素后面的屏幕。我在容器中嵌入了UIPageViewController
。然后我设置了一个UICollectionViewController
场景,在页面之间滑动时可以重复使用。这是通过代码完成的 - 见下文。基本上,它在屏幕上显示UICollectionViewController
。
它运行良好,除非它出现在屏幕上,它掩盖了主VC的UI。我可以更改高度以显示UI,但我确实希望它占据整个屏幕。我只是想让它躺在工具栏后面。这样,当用户滚动Collection VC时,内容将呈现在那些半透明工具栏下面。
我明白为什么它的行为方式如此,但我不知道如何解决它。我最初想的是因为它全部嵌入在Container中它会尊重该容器的z顺序,这在故事板中显得很好,但我想如果我只是在代码中将VC抛出到屏幕上,我应该期待这样的行为。我只是不确定如何获得理想的行为。谢谢你的帮助!
//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;
答案 0 :(得分:0)
我终于可以通过改变
来解决它[self.view addSubview:self.pageViewController.view];
到
[self.view insertSubview:self.pageViewController.view atIndex:1];