Swift 4 Pinch-to-Zoom带有滚动视图的视图

时间:2018-06-07 13:49:34

标签: ios swift uiscrollview swift4

如果我捏住模拟器,它就不起作用了!我想放大和缩小)=

这是我的代码:

import UIKit

class ViewController: UIViewController, UIScrollViewDelegate {

    @IBOutlet weak var scrollView: UIScrollView!

    let onView = UIView()

    override func viewDidLoad() {
        super.viewDidLoad()
        scrollView.delegate = self

        scrollView.contentSize.width = 10000
        scrollView.contentSize.height = 10000

        onView.frame = CGRect(x: 0, y: 0, width: scrollView.frame.width, height: scrollView.frame.height)

        scrollView.addSubview(onView)

        for _ in 1...1000{

            let x = arc4random_uniform(10000)
            let y = arc4random_uniform(10000)

            let btn = UIButton(frame: CGRect(x: Int(x), y: Int(y), width: Int(150), height: Int(100)))
            btn.backgroundColor = .red
            self.board.addSubview(btn)

        }

        scrollView.minimumZoomScale = 0.5
        scrollView.maximumZoomScale = 10.0
        scrollView.zoomScale = 1.0

    }

    func viewForZooming(in scrollView: UIScrollView) -> UIView? {
        return scrollView
    }
}

0 个答案:

没有答案