我正在为我的学校制作一个时间安排应用程序,并希望滚动浏览一周的日子。我每天都制作了一个View Controller,并将它们连接到UIPageViewController。我将过渡风格设置为“Scroll”并导航到“Horisontal”,但视图控制器无法正常渲染!但是,如果我将导航设置为“垂直”或将过渡样式设置为“Page Curl”,则可以正常工作!
Here is a gif of how it looks with the scroll transition
And here is a gif of how it looks with the page curl transition
所以我想知道,为什么它看起来很奇怪。以及如何解决它?
以下是我的PageViewController的一些代码:
let Sider = ["Mandag", "Tysdag", "Onsdag", "Torsdag", "Fredag"]
override func viewDidLoad() {
self.delegate = self
self.dataSource = self
}
override func viewWillAppear(_ animated: Bool) {
let cal = Calendar(identifier: .gregorian)
let date = Date()
let Vekedag = cal.component(.weekday, from: date)
if Vekedag == 7 || Vekedag == 1 {
print("Da e helg!!")
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Fredag") as UIViewController!
setViewControllers([vc!],
direction: .forward,
animated: true,
completion: nil)
}else if Vekedag == 2{
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Mandag") as UIViewController!
setViewControllers([vc!],
direction: .forward,
animated: true,
completion: nil)
}else if Vekedag == 3{
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Tysdag") as UIViewController!
setViewControllers([vc!],
direction: .forward,
animated: true,
completion: nil)
}else if Vekedag == 4{
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Onsdag") as UIViewController!
setViewControllers([vc!],
direction: .forward,
animated: true,
completion: nil)
}else if Vekedag == 5{
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Torsdag") as UIViewController!
setViewControllers([vc!],
direction: .forward,
animated: true,
completion: nil)
}else if Vekedag == 6{
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Fredag") as UIViewController!
setViewControllers([vc!],
direction: .forward,
animated: true,
completion: nil)
}
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
if let identifier = viewController.restorationIdentifier {
if let index = Sider.index(of: identifier) {
if index > 0 {
return self.storyboard?.instantiateViewController(withIdentifier: Sider[index-1])
}
}
}
return nil
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
if let identifier = viewController.restorationIdentifier {
if let index = Sider.index(of: identifier) {
if index < Sider.count - 1 {
return self.storyboard?.instantiateViewController(withIdentifier: Sider[index+1])
}
}
}
return nil
}
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return Sider.count
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
if let identifier = viewControllers?.first?.restorationIdentifier {
if let index = Sider.index(of: identifier) {
return index
}
}
return 0
}