寫了一個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) } }