gpt4 book ai didi

iOS/swift 3 : UIView too big within UIPageController

转载 作者:行者123 更新时间:2023-11-30 12:35:03 25 4
gpt4 key购买 nike

我在 ContainerView 中嵌入了 PageController。为什么我在 PageController 中显示的 View 没有缩放以适合 PageController?如何才能实现“规模适应”?(至少PageController本身会根据ContainerView调整其大小)

我的类(class)是:

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: IB结果黄色 View 被剪切而不是缩放以适应 PageController: Result wth the yellow view beeing cut instead of scaled to fit the PageController黄色 View 的约束: Constraints for the yellow view

最佳答案

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

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
}
}
}

关于iOS/swift 3 : UIView too big within UIPageController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42989106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com