其他分享
首页 > 其他分享> > UIScrollView 在手指点击的坐标处放大

UIScrollView 在手指点击的坐标处放大

作者:互联网

写了一个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)
    }
}

标签:zoomSize,zoomPoint,self,height,width,点击,坐标,UIScrollView,contentSize
来源: https://www.cnblogs.com/Free-Thinker/p/15800823.html