gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:19 25 4
gpt4 key购买 nike

我用多个 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 *)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 = [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:@"PertoView"];
return self.pertoView;
}
}


- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)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 *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)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

最佳答案

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

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

希望这个回答能帮到你,祝你好运

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com