Reputation: 283
I did a UIPageViewController
with multiple UIViewController
. And now, I need to add a fixed UIView
in top and in bottom in UIPageViewController
...
There's my code:
- (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];
}
}
In my UIStoryBoard
I have HomesViewController which is my UIPageViewController
, PertoViewController and RoteirosViewController. Both UIViewControllers
add in UIPageViewController
.
Upvotes: 3
Views: 1650
Reputation: 300
in viewDidAppear of the UIPagerViewController class add the 2 UIViews you want to add this should add the new views over already loaded views the 2 view controller.
if that didn't work for you make sure you add the 2 view controller also by code in not Storyboard and make sure to add them first then add the 2 views header and bottom one to make sure they are over the screens
hope this answer can help you and good luck
Upvotes: 1