正在剪切容器视图页面控制器而不是调整大小

问题描述 投票:2回答:1

我大约十五秒钟就没有翻过我的桌子而愤怒地放弃了,因为我无法弄明白这一点。

我有一个页面视图控制器作为容器视图控制器的嵌入。听起来很简单吧?

问题是,页面视图控制器正在被剪裁。我需要它来调整大小。因此,他们将是可爱的小页面,其中包含完整的VC内容。

我已经尝试了故事板显示器上的所有选项......事情。

这里有几个图片来描述这个问题:

The primary storyboard set up. Notice how the name of the Page View Controller is clipped. One of the view controllers I am trying to present as a page in the Page View Controller. Ignore its ugliness. How to aforementioned Page ends up when running the Simulator.

现在我将与您共享代码,但所有这些都是(单个)页面的加载。该页面确实存在于不同的故事板中,但即使我在主故事板中更改了View Controllers的视图,它们仍然被切断。

override viewDidLoad() {
let storyboard = UIStoryboard(name: "TEMPLATES", bundle: Bundle.main)

let vc = storyboard.instantiateViewController(withIdentifier: "template1")

self.setViewControllers([vc!], direction: UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil)

 self.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] //Some code I found on Stack Overflow that did nothing

 super.viewDidLoad()

}

任何帮助,将不胜感激!

ios iphone swift
1个回答
1
投票

如果你从故事板中添加它 - 它将起作用。

如果从代码中添加子视图控制器 - 您还需要像这样设置框架:

carsTableVC.view.frame = self.container.bounds

这是一个完整的代码示例(carsTableVC在容器中):

let sb = UIStoryboard.init(name: "Cars", bundle: nil)

self.carsTableVC =
    sb.instantiateViewController(withIdentifier:
        "CarsTableViewController") as? CarsTableViewController

carsTableVC.view.frame = self.container.bounds
carsTableVC.willMove(toParent: self)
addChild(carsTableVC)
carsTableVC.didMove(toParent: self)
container.addSubview(carsTableVC.view)
© www.soinside.com 2019 - 2024. All rights reserved.