禁用UIViewController中的滑动功能

时间:2015-11-18 12:57:26

标签: ios swift uipageviewcontroller

我有一个UIPageViewController,其中有两个 ViewControllers ,其中一个连接了 NavigationController ,所以我可以推送到另一个 ViewController 使用按钮中嵌入的 Push-Segue 。正在推送 ViewController 启用了UIPageViewController数据源,因此我可以从推送 ViewController 回到第一个 ViewController

我希望能够在推送 ViewController中禁用swip功能,所以我必须按后退按钮才能返回,而不是滑动。

我认为我的UIPageViewController未在之前的之后的功能中设置正确的视图。

代码 UIPageViewController

class upAndDownViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {



var pages = [UIViewController]()

override func viewDidLoad() {
    super.viewDidLoad()

    self.delegate = self
    self.dataSource = self

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



    pages.append(page2)
    pages.append(topPage)



    setViewControllers([page2], 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]


}

0 个答案:

没有答案