gpt4 book ai didi

ios - 页面 View ScrollView 不是锻炼

转载 作者:行者123 更新时间:2023-11-30 11:45:49 25 4
gpt4 key购买 nike

这是我的 pageView 代码。它不滚动。我正在使用 swift2,因为我的设置中没有 swift4。谁能帮助我,我是新鲜人!

import UIKit
class TutorialPageViewController:UIPageViewController,UIPageViewControllerDataSource,UIPageViewControllerDelegate
{

//Storyboard class and id -
//ViewController1,ViewController2,ViewController3

private(set) lazy var orderedViewControllers: [UIViewController] = {
return [self.newColoredViewController("ViewController1"),
self.newColoredViewController("ViewController2"),
self.newColoredViewController("ViewController3")]
}()

private func newColoredViewController(name: String) -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("name")
}

//code of pageview

override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
self.delegate = self

if let ViewController1 = orderedViewControllers.first {
setViewControllers([ViewController1],
direction: .Forward,
animated: true,
completion: nil)

}

}

最佳答案

您还需要实现 UIPageViewControllerDataSource :

extension Yourcontroller: UIPageViewControllerDataSource{


func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
return nil
}

let previousIndex = viewControllerIndex - 1

// User is on the first view controller and swiped left to loop to
// the last view controller.
guard previousIndex >= 0 else {
return orderedViewControllers.last
// Uncommment the line below, remove the line above if you don't want the page control to loop.
//return nil
}

guard orderedViewControllers.count > previousIndex else {
return nil
}

return orderedViewControllers[previousIndex]

}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
return nil
}
let nextIndex = viewControllerIndex + 1


let orderedViewControllersCount = orderedViewControllers.count

// User is on the last view controller and swiped right to loop to
// the first view controller.
guard orderedViewControllersCount != nextIndex else {
return orderedViewControllers.first
// Uncommment the line below, remove the line above if you don't want the page control to loop.
//return nil
}

guard orderedViewControllersCount > nextIndex else {
return nil
}

return orderedViewControllers[nextIndex]
}
}

关于ios - 页面 View ScrollView 不是锻炼,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48839911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com