标签:turn load can max delegate frame resources 最大 self
import UIKit
class ViewController: UIViewController ,UIScrollViewDelegate{
override func viewDidLoad() {
super.viewDidLoad()
let scrollView = UIScrollView.init()
scrollView.frame = self.view.bounds
let imageView = UIImageView.init(image: UIImage.init(named: "1"))
scrollView.contentSize = imageView.bounds.size
scrollView.addSubview(imageView)
self.view.addSubview(scrollView)
// 手势缩放大小
// 要实现放大缩小功能, 需要指定 UIScrollView 的允许缩放的最大和最小比例 (默认都是 1.0)
// 同时 delegate 属性指定一个委托类, 委托类要继承 UIScrollViewDelegate 协议, 并实现 viewForZooming 方法
scrollView.minimumZoomScale = 0.1 //最小比例
scrollView.maximumZoomScale = 3 //最大比例
scrollView.delegate = self
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
for subview : AnyObject in scrollView.subviews {
if subview.isKind(of: UIImageView.classForCoder()) {
return subview as? UIView
}
}
return nil
}
//视图滚动中一直触发
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("x:\(scrollView.contentOffset.x) y:\(scrollView.contentOffset.y)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
标签:turn load can max delegate frame resources 最大 self
原文地址:http://www.cnblogs.com/dingzhijie/p/6991946.html