【发布时间】:2020-08-19 12:34:43
【问题描述】:
我正在使用双击放大滚动视图内的图像视图。
当从按钮点击动作中调用下面的方法时,它可以正常工作(imageView 放大/缩小)。
但是我需要以编程方式调用该方法来放大,当我这样做时,什么也没有发生:imageView 没有放大。
我错过了什么?
下面是我使用的@objc func doubleTapped() 方法的精确副本,其中点击位置替换为任意CGPoint
func doubleTappedCustom() {
var scale: CGFloat = 2
let ratioW = imageView.frame.width / imageView.image!.size.width
let ratioH = imageView.frame.height / imageView.image!.size.height
let ratio = ratioW < ratioH ? ratioW:ratioH
let newWidth = imageView.image!.size.width * ratio
let newHeight = imageView.image!.size.height * ratio
if (imageView.image.size.width < imageView.size.height){
if scale > imageView.frame.width / newWidth {
scale = imageView.frame.width / newWidth
}
}
let location = CGPoint(x: imageView.frame.width/2, y: imageView.frame.height/2)
if scrollView.zoomScale == 1 {
// here tap location is repalced with 'location' cgpoint
scrollView.zoom(to: zoomRectForScale(scale, center: location), animated: true)
} else {
scrollView.setZoomScale(1, animated: true)
}
}
【问题讨论】:
标签: ios swift uiscrollview