我想用 UIPageViewController 和拖曳按钮(下一个和上一个)来显示 7 个不同内容的 View Controller ,这是我实现 UIPageViewController 后的 Storyboard。
我的问题是如何将这些 View Controller 放入 UIPageViewController 中?
用 Swift 回答:
在 UIPageVC 实例的 viewDidLoad 中调用 setViewControllers 方法来定义您的第一个 VC、方向等:
override func viewDidLoad() {
super.viewDidLoad()
dataSource = self
let vc = storyboard!.instantiateViewController(withIdentifier: "whatever storyboard id your first VC is")
setViewControllers([vc],
direction: .forward,
animated: false,
completion: nil)
}
使用 UIPageViewControllerDataSource 协议(protocol)方法来定义当前 viewController 之前和之后的页面以及 View Controller 计数和索引。
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController?
{
// Return some VC based on what the current viewController param is.
}
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController?
{
// Return some VC based on what the current viewController param is.
}
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return 7
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return viewControllers!.index(of: viewControllers!.first!)!
}
关于ios - 具有不同 ViewController 的 UIPageViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42160419/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |