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()
}
}
网友评论