我想在使用捏合手势放大或缩小后返回原始图像尺寸。
我发现类似的答案是
How to get original image when we zoom in and zoom out the image in ios,
它使用scrollView。不完全是我需要的。
这是我的代码,这是#selector
发送的手势响应func respondToGesture(_ gesture: UIGestureRecognizer) -> Void {
if let pinch = gesture as? UIPinchGestureRecognizer {
if let img = pinch.view as? UIImageView {
img.transform = CGAffineTransform(scaleX: pinch.scale, y: pinch.scale)
if pinch.state == .ended
{
img.transform = CGAffineTransform(scaleX: (1 / pinch.scale), y: (1 / pinch.scale))
}
}
}
}
希望得到一些建议!!感谢〜
答案 0 :(得分:1)
使用此功能重置图像大小
yourImage.transform = CGAffineTransform.identity
希望这有帮助!