【发布时间】:2021-03-05 06:14:46
【问题描述】:
我有以下代码:
func setUpPageController(viewControllers: [UIViewController]) {
let pagingViewController = PagingViewController(viewControllers: viewControllers)
pagingViewController.menuInsets = UIEdgeInsets(top: 1, left: 0, bottom: 1, right: 0)
pagingViewController.menuItemSize = .selfSizing(estimatedWidth: 100, height: 40)
pagingViewController.menuBackgroundColor = UIColor.Custom.secondaryColor_white
pagingViewController.selectedTextColor = UIColor.Custom.secondaryColor_black
pagingViewController.menuHorizontalAlignment = .center
pagingViewController.textColor = UIColor.Custom.secondaryColor_black
// Make sure you add the PagingViewController as a child view
// controller and contrain it to the edges of the view.
addChild(pagingViewController)
view.addSubview(pagingViewController.view)
pagingViewController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
pagingViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
pagingViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
pagingViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
pagingViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])
pagingViewController.didMove(toParent: self)
}
我想再次调用该函数,但在添加另一个子视图控制器之前删除了子视图控制器。因为第二次有不同的视图控制器会被添加或者只是一个不同的数组。
如果我在再次调用该方法时保持原样,则添加的前一个子项显示在滚动边缘的末尾或开头。
【问题讨论】:
标签: swift uipageviewcontroller childviewcontroller