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
?
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.
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.
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];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With