UIScrollView 在手指点击的坐标处放大(Uiscrollview zooms in at the coordinates clicked by the finger)

写了一个extension,如下:

extension UIScrollView{
    ///在ScrollView上的某个点放大
    func zoomWithPoint(var zoomPoint:CGPoint,toScale:CGFloat,animated:Bool){
        var contentSize:CGSize = CGSize.zeroSize
        contentSize.width = self.contentSize.width / self.zoomScale
        contentSize.height = self.contentSize.height / self.zoomScale
        zoomPoint.x = (zoomPoint.x / self.bounds.size.width) * contentSize.width
        zoomPoint.y = (zoomPoint.y / self.bounds.size.height) * contentSize.height
        var zoomSize:CGSize = CGSize.zeroSize
        zoomSize.width = self.bounds.size.width / toScale
        zoomSize.height = self.bounds.size.height / toScale
        var zoomRect:CGRect = CGRect.zeroRect
        zoomRect.origin.x = zoomPoint.x - zoomSize.width / 2.0
        zoomRect.origin.y = zoomPoint.y - zoomSize.height / 2.0
        zoomRect.size.width = zoomSize.width
        zoomRect.size.height = zoomSize.height
        self.zoomToRect(zoomRect, animated: animated)
    }
}
————————

An extension is written as follows:

extension UIScrollView{
    ///在ScrollView上的某个点放大
    func zoomWithPoint(var zoomPoint:CGPoint,toScale:CGFloat,animated:Bool){
        var contentSize:CGSize = CGSize.zeroSize
        contentSize.width = self.contentSize.width / self.zoomScale
        contentSize.height = self.contentSize.height / self.zoomScale
        zoomPoint.x = (zoomPoint.x / self.bounds.size.width) * contentSize.width
        zoomPoint.y = (zoomPoint.y / self.bounds.size.height) * contentSize.height
        var zoomSize:CGSize = CGSize.zeroSize
        zoomSize.width = self.bounds.size.width / toScale
        zoomSize.height = self.bounds.size.height / toScale
        var zoomRect:CGRect = CGRect.zeroRect
        zoomRect.origin.x = zoomPoint.x - zoomSize.width / 2.0
        zoomRect.origin.y = zoomPoint.y - zoomSize.height / 2.0
        zoomRect.size.width = zoomSize.width
        zoomRect.size.height = zoomSize.height
        self.zoomToRect(zoomRect, animated: animated)
    }
}