几个月前我刚开始使用swift进行编程,目前我正在开展一些随机项目来帮助我更好地学习语言。目前,我正在尝试使用UIPageViewController创建类似于Snapchat的UI。水平滚动工作正常,我可以正确浏览页面,但我想更改显示的初始视图控制器。在下面的代码中,我有三个ViewControllers(vc1,vc2,vc3)。我想保持它们的顺序相同,但首先显示vc2,所以基本上把它放在另外两个中间。所有帮助表示赞赏。谢谢!
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Self.Caption := IntToStr(X) + 'x' + IntToStr(Y);
end;
答案 0 :(得分:1)
您已准备好整个代码,您需要做的就是从viewDidLoad中的viewControllerList传递secondViewController,这是所有
所以替换
if let firstViewController = viewControllerList.first{
self.setViewControllers([firstViewController], direction: .forward, animated: true, completion: nil)
}
与
let secondViewController = viewControllerList[1]
self.setViewControllers([secondViewController], direction: .forward, animated: true, completion: nil)
希望这有帮助
答案 1 :(得分:-1)
这里我在swift 3中编写了一个扩展,用于在UIPageViewController中导航下一页和上一页。您可以根据需要进行修改。
扩展名UIPageViewController {
func goToNextPage(animated: Bool = true) {
guard let currentViewController = self.viewControllers?.first else { return }
guard let nextViewController = dataSource?.pageViewController(self, viewControllerAfter: currentViewController) else { return }
setViewControllers([nextViewController], direction: .forward, animated: animated, completion: nil)
}
func goToPreviousPage(animated: Bool = true) {
guard let currentViewController = self.viewControllers?.first else { return }
guard let previousViewController = dataSource?.pageViewController(self, viewControllerBefore: currentViewController) else { return }
setViewControllers([previousViewController], direction: .reverse, animated: animated, completion: nil)
}
}
我希望你觉得它很有用。 接受建议。