ios – 如何在水平UIPageViewController中实现垂直UIPageViewController

《ios – 如何在水平UIPageViewController中实现垂直UIPageViewController》

我想调整我的UIPageViewController工作就像在图像中一样,目前1b可以去2a等.我需要做什么来锁定图像中的方向?我忘了什么,或者我使用了错误的逻辑.任何小费都会有所帮助!

请注意,垂直UIPageViewController位于水平UIPageViewController内

水平UIPageViewController代码

class MyPageViewController: UIPageViewController , UIPageViewControllerDataSource, UIPageViewControllerDelegate {

var pages = [UIViewController]()

override func viewDidLoad() {
    super.viewDidLoad()

    self.delegate = self
    self.dataSource = self

    let page1: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("page1")
    let page2: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("page2")
    let page3: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("page3")


    pages.append(page1)
    pages.append(page2)
    pages.append(page3)


    setViewControllers([page2], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {


    let currentIndex = pages.indexOf(viewController)!


    let previousIndex = abs((currentIndex - 1) % pages.count)


    if (previousIndex > 0)
    {
        return nil
    }



    return pages[previousIndex]
}

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
    let currentIndex = pages.indexOf(viewController)!
    let nextIndex = abs((currentIndex + 1) % pages.count)


    if (nextIndex < 1)

    {
        return nil
    }

    return pages[nextIndex]

}

垂直UIPageViewController代码

class upAndDownViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

var pages = [UIViewController]()

override func viewDidLoad() {
    super.viewDidLoad()

    self.delegate = self
    self.dataSource = self

    let midPage: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("midPage")
    let topPage: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("topPage")



    pages.append(midPage)
    pages.append(topPage)



    setViewControllers([midPage], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)




}

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {


    let currentIndex = pages.indexOf(viewController)!
    let nextIndex = abs((currentIndex + 1) % pages.count)


    if (nextIndex < 1)
    {
        return nil
    }

    return pages[nextIndex]
}

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {

    let currentIndex = pages.indexOf(viewController)!


    let previousIndex = abs((currentIndex - 1) % pages.count)


    if (previousIndex > 0)
    {
        return nil
    }



    return pages[previousIndex]


}

最佳答案 我将水平UIPageViewController放在垂直的UIPageViewController中.修复它但由于某些原因,在TOP垂直UIPageViewController内部打开的其他ViewControllers能够向下翻页,我会更多地了解它并可能修复它.

点赞