我在ContainerView中嵌入了一个PageController。
为什么我在PageController中显示的视图无法缩放以适合PageController?我怎样才能达到“适应规模”?
(至少PageController本身会根据ContainerView调整其大小)

我的课程是:

import UIKit

class YellowController : UIViewController

{

}

class GreenController : UIViewController
{

}

//from a tutorial:
class PageController : UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate
{
// from stackoverflow to avoid the black box at the bottom of the pagecontroller
override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    for view in self.view.subviews
    {
        if view is UIScrollView
        {
            view.frame = UIScreen.main.bounds
        }
        else
        {
            view.backgroundColor = UIColor.clear
        }
    }
}


lazy var VCArray: [UIViewController] =
{
    return [self.VCInstance(name: "InfoPage"),
            self.VCInstance(name: "FragePage"),
            self.VCInstance(name: "AntwortPage") ]
}()

private func VCInstance (name: String) -> UIViewController
{
    let VCC = UIStoryboard(name: "Lerneinheit", bundle: nil).instantiateViewController(withIdentifier: name)

    return VCC
}

override func viewDidLoad() {
    super.viewDidLoad()
    self.dataSource = self
    self.delegate = self
    if let InfoPage = VCArray.first
    {
        setViewControllers([InfoPage], direction: .forward, animated: true, completion: nil)
    }
}


public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?
{
    guard let viewControllerIndex = VCArray.index(of: viewController)
    else
    {
        return nil
    }

    if (viewControllerIndex<1)
    {
        return nil
    }

    return VCArray[viewControllerIndex - 1]
}
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?
{
    guard let viewControllerIndex = VCArray.index(of: viewController)
        else
    {
        return nil
    }

    if viewControllerIndex == VCArray.count-1
    {
        return nil
    }

    return VCArray[viewControllerIndex + 1]
}

public func presentationCount(for pageViewController: UIPageViewController) -> Int
{
    return VCArray.count
}

public func presentationIndex(for pageViewController: UIPageViewController) -> Int
{
    guard let firstViewController = viewControllers?.first, let firstViewControllerIndex = VCArray.index(of: firstViewController)
    else
    {
        return 0
    }

    return firstViewControllerIndex
}


IB:
ios - iOS/Swift 3:UIPageController中的UIView太大-LMLPHP
黄色视图蜂切掉的结果,而不是缩放以适合PageController的结果:
ios - iOS/Swift 3:UIPageController中的UIView太大-LMLPHP
黄色视图的约束:
ios - iOS/Swift 3:UIPageController中的UIView太大-LMLPHP

最佳答案

下面的代码是多余的,将其删除:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    for view in self.view.subviews
    {
        if view is UIScrollView
        {
            view.frame = UIScreen.main.bounds
        }
        else
        {
            view.backgroundColor = UIColor.clear
        }
    }
}

10-06 12:33