美文网首页
UIScrollView

UIScrollView

作者: 79d12e22ec53 | 来源:发表于2019-04-24 18:00 被阅读0次

    UIScrollView

    scrollView.frame
    scrollView.isPagingEnable = true
    scrollView.contentSize = CGSize() //设置滚动范围
    scrollView.delegate = self
    
    pageControl.frame
    pageControl.numberOfPages
    pageControl.currentPage
    pageControl.addTarget
    
    @objc func PageControlDidChanged() {
      let crtPage = scrollView.currentPage
      var frame = scrollView.frame
      frame.origin.x = frame.size.width * crtPage
      frame.origin.y = 0
      
      scrollView.scrollRectToVisible(frame, animated: true)
      isPageControlUsed = true
    }
    
    func scrollViewDidScroll() {
      if(!isPageControlUsed) {
        let pageWidth = scrollView.frame.size.width
        let page = floor(scrollView.contentOffset.x - pageWidth/2)/pageWidth + 1
        pageControl.currentPage = page
      }
      
      func scrollViewDidEndDecelerating() {
        isPageControlUsed = false
      }
    }
    

    相关文章

      网友评论

          本文标题:UIScrollView

          本文链接:https://www.haomeiwen.com/subject/jthngqtx.html