How to enable user interaction for ViewControllers views inside UIPageViewContrller in swift

Viewed 288

I am trying to to add UIPageViewController as a child to the MainViewController, the UIPageViewController has 2 ViewContrllers, the problem is I can't interact with any of the views that belong to the view controllers of the ui page view controller, can't press buttons I tried to make userInteraction enabled for all the views inside the UIPageView Controller also tried the NSLayoutConstraint but couldn't get it to work , this is the way i added the ui page view controller to the main controller as a child

let uiPC = MyUIPageViewController(vm: vm)
uiPC.view.frame = containerView.frame
containerView.addSubview(uiPC.view)
addChild(uiPC)
uiPC.didMove(toParent: self)

also tried the constraint solution to set the view of the page controller with the view of the container view but no luck, can't get the user interaction to be enabled. the only way that work is either adding the views of the ViewControllers as a subview or add the 2 view controller of UIPageviewContoller as a child to the MainViewController adding the UIPageViewController as a child inside the MainViewController

1 Answers

That is the expected behaviour of UIPageViewController in tvOS:

From the documentation:

Important 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.

At the end I managed to get my design by embedding 2 view controllers in my view controller. A not interactive UIPageViewController in the background for the different pages, and another view controller on top with the buttons and clear background.

I also tried to implement an interactive UIPageViewController by using a UICollectionView with fullscreen cells and isPagingEnabled set to true. But, as documented, that is again not that easy in tvOS because isPaging is no available in tvOS.

Related