Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 249
Add080bbA Avatar asked Oct 28 '14 09:10

Add080bbA


People also ask

How Does UIPageViewController work?

When navigating from page to page, the page view controller uses the transition that you specify to animate the change. In tvOS, the UIPageViewController class provides only a way to swipe between full-screen content pages. Unlike in iOS, a user cannot interact with or move focus between items on each page.

What is a page view controller?

The PageViewController is used in many of the iOS applications to let the user navigate between the various pages of the content of the application. The navigation can be controlled programmatically in the application. The PageViewController uses the transition that we specify to animate the change.


2 Answers

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];
like image 108
Michał Ciuba Avatar answered Oct 30 '22 01:10

Michał Ciuba


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.

like image 39
Oscar Avatar answered Oct 30 '22 01:10

Oscar