Swift 4:具有分页功能的水平滚动视图

时间:2018-07-29 14:55:46

标签: ios swift charts uiscrollview swift4

我有带有快速图表的UIView控制器,一方面必须具有垂直滚动,但是另一方面,它的一部分也应具有水平页面滚动视图。 我的VC场景如下所示: enter image description here

我的垂直滚动视图效果很好,但是this tutorial创建的水平滚动视图不想滚动

我的代码是:

override func viewDidLoad() {
    super.viewDidLoad()
    pagingScrollView.delegate = self
    let slides =   self.createSlides((data!)
    setupSlideScrollView(slides: slides)
    pageControl.numberOfPages = slides.count
    pageControl.currentPage = 0
    pagingScrollView.bringSubview(toFront: pageControl)    
}

private func createSlides(_ exercisesData: [MyData]) -> [UIView] {
    let slide1 = Bundle.main.loadNibNamed("SummaryStackedChartView", owner: self, options: nil)?.first as! SummaryStackedChartView
    slide1.stackedBarData = exercisesData
    let slide2 = Bundle.main.loadNibNamed("SummaryStackedChartView", owner: self, options: nil)?.first as! SummaryStackedChartView
    slide2.stackedBarData = exercisesData
    return [slide1, slide2]//just for checking slider add same view
}

private func setupSlideScrollView(slides: [UIView]) {          
    pagingScrollView.frame = CGRect(x: 0, y: pagingScrollView.frame.origin.y, width: view.frame.width, height: pagingScrollView.frame.height)

    pagingScrollView.contentSize = CGSize(width: view.frame.width * CGFloat(slides.count), height: pagingScrollView.frame.height)
    pagingScrollView.isPagingEnabled = true

    for i in 0 ..< slides.count {
        slides[i].frame = CGRect(x: view.frame.width * CGFloat(i), y: 0, width: view.frame.width, height: pagingScrollView.frame.height)
        pagingScrollView.addSubview(slides[i])
        if let slide = slides[i] as? SummaryStackedChartView {
            slide.initChart()
        }    
    }
}

以下视图的结果,但是滚动分页不起作用。是否可以创建这样的结构,使其包含垂直滚动视图,并在其中包含水平滚动视图?因为我认为问题不在我的代码中,但实际上垂直滚动视图以某种方式限制了这种行为

enter image description here

0 个答案:

没有答案