美文网首页
滚动视图(UIScrollView)

滚动视图(UIScrollView)

作者: 焉逢12 | 来源:发表于2017-03-04 14:32 被阅读0次
    import UIKit
     
    class ViewController: UIViewController, UIScrollViewDelegate {
         
        var scrollView:UIScrollView!
         
        override func viewDidLoad() {
            super.viewDidLoad()
             
            scrollView = UIScrollView()
            //设置代理
            scrollView.delegate = self
            scrollView.frame = self.view.bounds
            let imageView = UIImageView(image:UIImage(named:"bigpic.jpg"))
            scrollView.contentSize = imageView.bounds.size
            scrollView.addSubview(imageView)
            self.view.addSubview(scrollView)
        }
         
        //视图滚动中一直触发
        func scrollViewDidScroll(_ scrollView: UIScrollView) {
            print("x:\(scrollView.contentOffset.x) y:\(scrollView.contentOffset.y)")
        }
         
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
        }
    }
    

    相关文章

      网友评论

          本文标题:滚动视图(UIScrollView)

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