gpt4 book ai didi

swift - UIImageView 捏缩放 swift

转载 作者:IT王子 更新时间:2023-10-29 05:00:02 25 4
gpt4 key购买 nike

我希望有人能帮助我。我试图让用户在 UIImageView 上捏缩放(允许最大和最小级别)。但由于某种原因,它不能正常工作。图像放大一点然后反弹回来。谢谢。

这是缩放功能

func zoom(sender:UIPinchGestureRecognizer) {


if sender.state == .Ended || sender.state == .Changed {

let currentScale = self.view.frame.size.width / self.view.bounds.size.width
var newScale = currentScale*sender.scale

if newScale < 1 {
newScale = 1
}
if newScale > 9 {
newScale = 9
}

let transform = CGAffineTransformMakeScale(newScale, newScale)

self.imageView?.transform = transform
sender.scale = 1

}

}

最佳答案

用 UIScrollView 缩放 UIImageView || swift 3 和 Xcode 8 字母中的图像缩放 ios Youtube video URL

在 storyboard 中设置 uiscrollview Delegate enter image description here

 class PhotoDetailViewController: UIViewController, UIScrollViewDelegate {

@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var imgPhoto: UIImageView!

override func viewDidLoad() {

super.viewDidLoad()

scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 6.0
// scrollView.delegate = self - it is set on the storyboard.
}

func viewForZooming(in scrollView: UIScrollView) -> UIView? {

return imgPhoto
}

关于swift - UIImageView 捏缩放 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com