• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - UIPageViewController 与多个 UIViewController 与标题和底栏

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:49:51 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我用多个 UIViewController 做了一个 UIPageViewController。现在,我需要在 UIPageViewController 的顶部和底部添加一个固定的 UIView...

这是我的代码:

   - (void)viewDidLoad
{
    [super viewDidLoad];

    // Create it.
    self.pageController = [[UIPageViewController alloc] 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 = [UIStoryboard storyboardWithName"Main" bundle:nil];
    if(!self.roteirosView)
        self.roteirosView = [sb instantiateViewControllerWithIdentifier"RoteirosView"];

    self.initialViewControllers = [NSArray arrayWithObject:self.roteirosView];

    // animated:NO is important so the view just pops into existence.
    // direction: doesn't matter because it's not animating in.
    [self.pageController setViewControllers:self.initialViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

    // Tell the child view to get ready
    [self.pageController willMoveToParentViewController:self];

    // Actually add the child view controller
    [self addChildViewController:self.pageController];

    // Don't forget to add the new root view to the current view hierarchy!
    [self.view addSubview:self.pageController.view];

    // And make sure to activate!
    [self.pageController didMoveToParentViewController:self];
}

- (void)viewDidLayoutSubviews {
}

- (UIViewController *)viewControllerAtIndexint)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 = [UIStoryboard storyboardWithName"Main" bundle:nil];

    if (i == 0) {
        if(!self.roteirosView)
            self.roteirosView = [sb instantiateViewControllerWithIdentifier"RoteirosView"];
        return self.roteirosView;
    }
    else {
        if(!self.pertoView)
            self.pertoView = [sb instantiateViewControllerWithIdentifier"ertoView"];
        return self.pertoView;
    }
}


- (UIViewController *)pageViewControllerUIPageViewController *)pageViewController viewControllerBeforeViewControllerUIViewController *)viewController {
    UIViewController *p = (UIViewController *)viewController;
    if ([p isKindOfClass:[PertoViewController class]]) {
        return [self viewControllerAtIndex:0];
    }
    else {
        return [self viewControllerAtIndex:MAX_PAGES]; // permanece na mesma página
    }

}


- (UIViewController *)pageViewControllerUIPageViewController *)pageViewController viewControllerAfterViewControllerUIViewController *)viewController {
    UIViewController *p = (UIViewController *)viewController;
    if ([p isKindOfClass:[PertoViewController class]]) {
        return [self viewControllerAtIndex:MAX_PAGES]; // permanece na mesma página
    }
    else {
        return [self viewControllerAtIndex:1];
    }
}

在我的 UIStoryBoard 中有 HomesViewController,它是我的 UIPageViewController、PertoViewController 和 RoteirosViewController。 UIViewControllers 都添加在 UIPageViewController 中。



Best Answer-推荐答案


在 UIPagerViewController 类的 viewDidAppear 中添加您要添加​​的 2 个 UIView,这应该在 2 个 View Controller 中添加新 View 而不是已加载的 View 。

如果这对您不起作用,请确保您也通过代码而不是 Storyboard 中的代码添加 2 个 View Controller ,并确保先添加它们,然后添加 2 个 View 标题和底部一个以确保它们在屏幕上

希望这个答案可以帮助你,祝你好运

关于ios - UIPageViewController 与多个 UIViewController 与标题和底栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31965739/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap