嵌入在containerView中的PageViewController显示先前视图的小边距

时间:2016-01-19 14:42:33

标签: ios swift uipageviewcontroller

我创建了一个带有containerView的viewController,我在其中嵌入了一个pageViewController。在这个页面控制器里面我添加了3个viewControllers。这似乎工作正常,但每次我刷到下一个视图时,它似乎在前一个视图的一侧显示一点边距。什么可能导致这种情况?

enter image description here

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 个答案:

答案 0 :(得分:1)

您可能会谈论页面间距。您可以在故事板中对其进行编辑。选择“页面视图控制器”,然后打开“属性”检查器。会有相应的部分:

enter image description here