swift ScrollView

 var socrView = UIScrollView(frame:CGRect(x:10,y:10,width:100,height:100))
        //内容大小
        socrView.contentSize = CGSize(width:100,height:200);
        //可以上下滚动
        socrView.isScrollEnabled = true;
        //会滚到顶点
        socrView.scrollsToTop = true;
        //反弹效果
        socrView.bounces = true;
        //分页显示
        socrView.isPagingEnabled = true;
        //水平/垂直滚动条是否可见
        socrView.showsVerticalScrollIndicator = true;
        socrView.showsHorizontalScrollIndicator = true;
        //滚动条颜色
        socrView.indicatorStyle = .white;

代理

 //MARK:--scrollview代理
    //只要滚动一直触发contentOffset变化
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        print("只要滚动就会触发")
    }
    //用户开始拖动scrollview时候被调用
    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
      print("开始拖拽试图")
    }

    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        print("结束滚动")
    }

    func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
        print("将要开始减速")
    }
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        print("减速停止了时执行,手触摸时执行执行")
    }

    func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
        print("滚动动画停止时执行,代码改变时触发,也就是setContentOffset改变时")
    }

    func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
        print("完成放大缩小时调用")
    }

你可能感兴趣的:(Swift4.0学习笔记)