下面的代碼按照預期在第一次從相機膠捲中選取圖像時運行。縮小圖像以適應scrollView。但是當我再次運行它來重新拍攝圖像並再次選擇相同的圖像時,它會放大到1.0的比例。無法弄清楚我需要重新設置以使其每次都能保持一致。有任何想法嗎?UIScrollView zoomScale不一致
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
scrollView.contentSize = CGSize(width: 0, height: 0)
picView.image = nil
picView.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
picView.removeFromSuperview()
self.dismissViewControllerAnimated(true, completion: nil)
scrollView.addSubview(picView)
scrollView.contentSize = image.size
let scaleWidth = scrollView.frame.size.width/scrollView.contentSize.width //image.size.width
let scaleHeight = scrollView.frame.size.height/scrollView.contentSize.height //image.size.height
let minScale = min(scaleWidth, scaleHeight)
scrollView.minimumZoomScale = minScale
scrollView.maximumZoomScale = 1.0
scrollView.zoomScale = minScale
}
調試告訴你什麼? minScale的值是否正確出來? – matt
是的,最小比例值總是相同&正確的,但我懷疑scrollView contentSize會以某種方式被搞亂。即使縮放比例正確,這會影響縮放嗎? – Kashif
對,因爲這就是縮放的工作原理。 – matt