Reputation: 1876
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
?
Upvotes: 5
Views: 4487
Reputation: 2325
Although the answer is technically yes, UIPageViewController will position its pages at the top of the screen even if its own frame begins farther down the screen. The result is that the top of your pages will be cut off.
I've attempted to work around this by setting the frame of the loaded pages to match that of the pageController's view, but encountered several problems. One of them is that the frame isn't set until the view appears, causing a visible shift. You can't use viewWillAppear to prevent this because that's not called on the pageView controller, but rather on the children.
You can work around this by laying out your pages to shift all of their content down far enough to come into view, but of course that's a hard-coded solution that isn't very flexible.
There may be a programmatic solution; I considered putting the content on each page onto a UIScrollView and trying to find a time to set the content offset based on the runtime frame of the UIPageView.
Upvotes: 1
Reputation: 7944
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];
Upvotes: 7