我有一个带有3个页面的简单UIPageViewController,它们全部ViewControllers
嵌入在NavigationControllers
中。
当我滚动浏览这些页面时,在整个滚动过程中,右侧页面的背后都有黑色背景。控制器卡入到位后,它将恢复正常。
我该如何解决?
已解决:UIPageViewController
的子类中:self.view.backgroundColor = .white
代码:
lazy var viewControllerList: [UIViewController] = {
let sb = UIStoryboard(name: "Main", bundle: nil)
let yesterdayVC = sb.instantiateViewController(withIdentifier: "Yesterday")
let todayVC = sb.instantiateViewController(withIdentifier: "Today")
let tomorrowVC = sb.instantiateViewController(withIdentifier: "Tomorrow")
return [yesterdayVC, todayVC, tomorrowVC]
}()
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
setViewControllers([viewControllerList[1]], direction: .forward, animated: true, completion: nil)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let vcIndex = viewControllerList.firstIndex(of: viewController) else { return nil }
let previousIndex = vcIndex - 1
guard previousIndex >= 0 else { return nil }
guard viewControllerList.count > previousIndex else { return nil }
return viewControllerList[previousIndex]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let vcIndex = viewControllerList.firstIndex(of: viewController) else { return nil }
let nextIndex = vcIndex + 1
guard viewControllerList.count > nextIndex else { return nil }
return viewControllerList[nextIndex]
}
编辑:将视图置于NavigationControllers或PageViewController后面无济于事。无论PageViewController背景是什么颜色,颜色始终为黑色。
答案 0 :(得分:0)
将UIPageViewController
子类化,并在viewDidLoad()
中调用self.view.backgroundColor = .white
。这应该可以解决您的问题。
答案 1 :(得分:0)
UIPageViewController
的视图是透明的,因此您看到的黑色是窗口。因此,只需在您的应用程序委托或场景委托中更改Windows背景颜色,例如
self.window.backgroundColor = UIColor.whiteColor;