如何将我的scrollView与我的PageController连接? (迅速)

时间:2014-12-23 21:36:50

标签: swift uiscrollview uipageviewcontroller

好吧所以我在尝试让我的pageControl与我的卷轴配合时遇到了麻烦。我尝试了不同的功能,但我似乎能把它弄好。我可以调用适量的视图,例如白点与我拥有的图片数量相匹配,但是当我从一张图片滚动到另一张图片时,点不会移动。你如何将我的pageControl连接到我的滚动,所以当我向左和向右滚动它会响应pageControl?

// Number of views
                var numberOfViews = picSource.count    
                var picNum:CGFloat = CGFloat(picSource.count)
// Image Scroller
                let scroll = UIScrollView(frame:CGRectMake(-5, 650, screenWidth, 260))
                scroll.pagingEnabled = true
                scroll.showsHorizontalScrollIndicator = false
                scroll.showsVerticalScrollIndicator = false
                scroll.contentSize = CGSizeMake(picNum*screenWidth, 220)
                scroll.delegate = self

                let pageControl = UIPageControl(frame: CGRectMake(0, 600, 100, 25))
                pageControl.numberOfPages = numberOfViews
                pageControl.currentPage = 0
                pageControl.addTarget(self, action: "pageControlSwipe:", forControlEvents: UIControlEvents.ValueChanged)
                pageControl.backgroundColor = UIColor.redColor()
                pageControl.userInteractionEnabled = true
                self.view.bringSubviewToFront(pageControl)
                border.addSubview(pageControl)

// pageControl swipe
                func pageControlSwipe(sender: AnyObject) -> () {
                    let x = CGFloat(pageControl.currentPage) * scroll.frame.size.width
                    scroll.setContentOffset(CGPointMake(x, 0), animated: true) 
                }

                func scrollViewDidEndDecelerating(scroll: UIScrollView) -> () {
                    let pageNumber = round(scroll.contentOffset.x / (scroll.frame.size.width))
                    pageControl.currentPage = Int(pageNumber)
                }

1 个答案:

答案 0 :(得分:0)

使用PageController连接ScrollView请参阅链接...
link here

在这里有Main ScrollView - > PageController - > SubScrollView - > UIImageView - >的UIImage