UIScrollView中的UIPageviewController

时间:2015-04-17 17:27:30

标签: ios swift uiscrollview uipageviewcontroller

我想快速编写一个读者代码。 我为此使用了pageViewController。要在使用UIscrollView时启用ZoomIN / ZoomOut,我的想法是在这个scrollView中放入pageViewController。

实际上,它有效。但我的问题只出在屏幕上的位置,裁剪了网页浏览控制器。

我的代码:

class RootViewController: UIViewController, 
      UIPageViewControllerDelegate, 
      UIPageViewControllerDataSource, 
      UIScrollViewDelegate 
 {

  @IBOutlet weak var scrollView: UIScrollView!
  var isLandscape:Bool = Bool()
  var pageData:[String] = []
  var pageViewController:UIPageViewController = UIPageViewController()

  //MARK: ViewDid/Should methods
  override func viewDidLoad() {

    super.viewDidLoad()
    scrollView.delegate = self

    loadData()    // Load the images URL

    // Set up the pageViewController
    pageViewController = UIPageViewController(transitionStyle: UIPageViewControllerTransitionStyle.PageCurl, navigationOrientation: UIPageViewControllerNavigationOrientation.Horizontal, options: nil)
    pageViewController.delegate = self
    pageViewController.dataSource = self

    var startingViewController:DataViewController = self.viewControllerAtIndex(0) as DataViewController

    var viewControllers = [startingViewController] as NSArray
    pageViewController.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)

    self.addChildViewController(pageViewController)
    self.contentView.addSubview(pageViewController.view)
    // Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
    var pageViewRect:CGRect = self.view.bounds
    pageViewRect = CGRectInset(pageViewRect, 10.0, 20.0)
    self.view.frame = pageViewRect
    self.pageViewController.didMoveToParentViewController(self)

    scrollView.minimumZoomScale = 1
    scrollView.maximumZoomScale = 2.5
    scrollView.zoomScale = 1
    scrollView.setZoomScale(1.0, animated:false)

 }
}



 func viewForZoomingInScrollView(scrollView:UIScrollView) -> UIView {
    // Return the view that you want to zoom
    return pageViewController.view
  }

截图: enter image description here

有人可以帮我解决这个问题。 感谢。

0 个答案:

没有答案