ios - UIPageViewController 与多个 UIViewController 与标题和底栏
<p><p>我用多个 <code>UIViewController</code> 做了一个 <code>UIPageViewController</code>。现在,我需要在 <code>UIPageViewController</code> 的顶部和底部添加一个固定的 <code>UIView</code>...</p>
<p>这是我的代码:</p>
<pre><code> - (void)viewDidLoad
{
;
// Create it.
self.pageController = [ initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
// Point the datasource back to this UIViewController.
self.pageController.dataSource = self;
// Assuming you have a SomePageViewController which extends UIViewController so you can do custom things.
UIStoryboard *sb = ;
if(!self.roteirosView)
self.roteirosView = ;
self.initialViewControllers = ;
// animated:NO is important so the view just pops into existence.
// direction: doesn't matter because it's not animating in.
;
// Tell the child view to get ready
;
// Actually add the child view controller
;
// Don't forget to add the new root view to the current view hierarchy!
;
// And make sure to activate!
;
}
- (void)viewDidLayoutSubviews {
}
- (UIViewController *)viewControllerAtIndex:(int)i {
// Asking for a page that is out of bounds??
if (i<0) {
return nil;
}
if (i>=MAX_PAGES) {
return nil;
}
// Assuming you have SomePageViewController.xib
UIStoryboard *sb = ;
if (i == 0) {
if(!self.roteirosView)
self.roteirosView = ;
return self.roteirosView;
}
else {
if(!self.pertoView)
self.pertoView = ;
return self.pertoView;
}
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
UIViewController *p = (UIViewController *)viewController;
if (]) {
return ;
}
else {
return ; // permanece na mesma página
}
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
UIViewController *p = (UIViewController *)viewController;
if (]) {
return ; // permanece na mesma página
}
else {
return ;
}
}
</code></pre>
<p>在我的 <code>UIStoryBoard</code> 中有 HomesViewController,它是我的 <code>UIPageViewController</code>、PertoViewController 和 RoteirosViewController。 <code>UIViewControllers</code> 都添加在 <code>UIPageViewController</code> 中。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在 UIPagerViewController 类的 viewDidAppear 中添加您要添加的 2 个 UIView,这应该在 2 个 ViewController 中添加新 View 而不是已加载的 View 。</p>
<p>如果这对您不起作用,请确保您也通过代码而不是 Storyboard 中的代码添加 2 个 ViewController ,并确保先添加它们,然后添加 2 个 View 标题和底部一个以确保它们在屏幕上</p>
<p>希望这个答案可以帮助你,祝你好运</p></p>
<p style="font-size: 20px;">关于ios - UIPageViewController 与多个 UIViewController 与标题和底栏,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31965739/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31965739/
</a>
</p>
页:
[1]