我想在特定视图中修复PageViewController视图。当我加载到ViewController主视图中时,它工作正常,但是当我将其加载到subView中时,PageViewController无法在该subView中修复。如何在子视图中修复PageViewController。
图像1,红色视图是我的子视图,我想在此红色视图中修复PageViewController。
图片2,这是我得到的。
答案 0 :(得分:1)
根据另一个问题中的代码,您正在将页面视图添加到(红色)子视图中,但未设置其框架。
// Create the page container
pageContainer = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
pageContainer.delegate = self
pageContainer.dataSource = self
pageContainer.setViewControllers([page1], direction: UIPageViewController.NavigationDirection.forward, animated: false, completion: nil)
// Add it to the view
pageControllerView.addSubview(pageContainer.view)
// set the frame of the pageContainer view to match its superview (the red view)
pageContainer.view.frame = pageControllerView.bounds
// let it resize if needed (such as device rotation)
pageContainer.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
此应解决该问题。