UIPageViewController不会停止滚动

时间:2015-07-12 21:03:31

标签: ios xcode swift debugging uipageviewcontroller

我正在使用UIPageController,其中包含2个图像。在运行应用程序时,UIPageController完美地显示第一页,但随后从第二页无限滚动。它保持相同的图像,并且即使在达到极限后仍继续显示相似的图像。它仅更改第一次滑动的图像,然后既不会更改图像也不会还原为后续滚动中的初始图像。

鉴于是来源。请帮忙。

  import UIKit
  class SignUpViewController: UIViewController, UIPageViewControllerDataSource {
  var pageViewController : UIPageViewController!
   var InfoImages : NSArray!

  override func viewDidLoad() {
    super.viewDidLoad()


    self.InfoImages = NSArray(objects: "blue","red")

    self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("IntroPageController") as! UIPageViewController
    self.pageViewController.dataSource = self

    let startVC = self.viewControllerAtIndex(0) as ContentViewController
    let viewControllers = NSArray(object: startVC)

    self.pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: .Forward, animated: true, completion: nil)

    self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)

    self.addChildViewController(self.pageViewController)
    self.view.addSubview(self.pageViewController.view)
    self.pageViewController.didMoveToParentViewController(self)

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func viewControllerAtIndex(index: Int) -> ContentViewController
{
    if ((self.InfoImages.count == 0) || (index >= self.InfoImages.count)){
        return ContentViewController()
    }

    let info = storyBoard.instantiateViewControllerWithIdentifier("ContentViewController") as! ContentViewController

    info.imageFile = self.InfoImages[index] as! String

    return info



}

//MARK : -DataSource

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
{
    let vc = viewController as! ContentViewController
    var index = vc.pageIndex as Int

    if( index == 0 || index == NSNotFound ){
        return nil
    }
    index--
    return self.viewControllerAtIndex(index)

}

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?
{
    let vc = viewController as! ContentViewController
    var index = vc.pageIndex as Int

    if( index == NSNotFound ){

        return nil

    }

    index++
    if(index == self.InfoImages.count){
        return nil
    }

    return self.viewControllerAtIndex(index)

}


@available(iOS 6.0, *)
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int

{
    return self.InfoImages.count
}


@available(iOS 6.0, *)
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int
{
    return 0
}

@IBAction func SkipInfo(sender: AnyObject) {

    let skipinfo = storyBoard.instantiateViewControllerWithIdentifier("afterLoginview") as! LoginViewController
    self.presentViewController(skipinfo , animated: true, completion: nil)
}

提前干杯谢谢!

P.S:我正在使用Xcode 7.0 beta(swift 2.0)

0 个答案:

没有答案