嵌入在 containerView 中的 PageViewController 显示前一个视图的小边距
Posted
技术标签:
【中文标题】嵌入在 containerView 中的 PageViewController 显示前一个视图的小边距【英文标题】:PageViewController embedded in containerView shows small margin of previous view 【发布时间】:2016-01-19 14:42:32 【问题描述】:我创建了一个带有 containerView 的 viewController,我在其中嵌入了 pageViewController。在这个 pageController 中,我在里面添加了 3 个 viewController。这似乎工作正常,但是每次我滑动到下一个视图时,它似乎在前一个视图的一侧显示了一点边距。这是什么原因造成的?
ViewDidLoad
if let firstViewController = orderedViewControllers.first
self.pageViewController?.setViewControllers([firstViewController],
direction: .Forward,
animated: true,
completion: nil)
newViewController
func newViewController(view: String) -> UIViewController
return UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier(view)
PageControllerDelegate
extension CameraViewController: UIPageViewControllerDataSource
func pageViewController(pageViewController: UIPageViewController,
viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
guard let viewControllerIndex = orderedViewControllers.indexOf(viewController) else
return nil
let previousIndex = viewControllerIndex - 1
// User is on the first view controller and swiped left to loop to
// the last view controller.
guard previousIndex >= 0 else
return orderedViewControllers.last
guard orderedViewControllers.count > previousIndex else
return nil
return orderedViewControllers[previousIndex]
func pageViewController(pageViewController: UIPageViewController,
viewControllerAfterViewController viewController: UIViewController) -> UIViewController?
guard let viewControllerIndex = orderedViewControllers.indexOf(viewController) else
return nil
let nextIndex = viewControllerIndex + 1
let orderedViewControllersCount = orderedViewControllers.count
// User is on the last view controller and swiped right to loop to
// the first view controller.
guard orderedViewControllersCount != nextIndex else
return orderedViewControllers.first
guard orderedViewControllersCount > nextIndex else
return nil
return orderedViewControllers[nextIndex]
【问题讨论】:
【参考方案1】:您可能谈到了页面间距。您可以在情节提要中对其进行编辑。选择您的页面视图控制器,然后打开属性检查器。会有相应的部分:
【讨论】:
以上是关于嵌入在 containerView 中的 PageViewController 显示前一个视图的小边距的主要内容,如果未能解决你的问题,请参考以下文章
Swift:如何将数据传递给嵌入在 ContainerView 中的 PageViewController?
ContainerView 内的嵌入式 UICollectionView - 关于旋转问题
ContainerView中嵌入的iOS7 SplitviewController不旋转