我的UIImageView包含在UIScrollView中。
scrollView.minimumZoomScale = 1.0
当我尝试缩小图像时,图像的大小等于50%。 当我移开手指时,图像的大小再次等于100%。
如何在缩放过程中防止缩小小于100%?
override func awakeFromNib() {
super.awakeFromNib()
scrollView.delegate = self
scrollView.addSubview(imgView)
scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 5.0
scrollView.zoomScale = 1.0
centerScrollViewContents()
}
func centerScrollViewContents() {
let boundsSize = scrollView.bounds.size
var contentsFrame = imgView.frame
if contentsFrame.size.width < boundsSize.width {
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0
} else {
contentsFrame.origin.x = 0.0
}
if contentsFrame.size.height < boundsSize.height {
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0
} else {
contentsFrame.origin.y = 0.0
}
imgView.frame = contentsFrame
}