Search code examples
iosobjective-cswiftuipageviewcontroller

Does UIPageViewController have to be full screen?


Does UIPageViewController have to be full screen ? May it be embedded in a smaller rectangle in other visual containers such as a corner of a UIView, UINavigationController or UITabBarController ?


Solution

  • No, it doesn't have to be full screen. In fact it can be used as any other UIViewController. If you want to embed it in a smaller rectangle, you can use UIViewController containment.

    Let's assume that you want to embed it into a parent controller which is a UIViewController subclass. Then define a pageViewController property and add it as a child view controller in viewDidLoad:

    self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    self.pageViewController.view.frame = ... //set the frame or add autolayout constraints
    
    [self addChildViewController:self.pageViewController];
    [self.view addSubview:self.pageViewController.view];
    [self.pageViewController didMoveToParentViewController:self];