gpt4 book ai didi

快速捏缩放

转载 作者:行者123 更新时间:2023-11-28 13:32:32 25 4
gpt4 key购买 nike

我正在尝试以编程方式将图像和 ScrollView 添加到 swift,然后将它们捏合以进行缩放。

我已按照 UIImageView pinch zoom swift 中的说明进行操作但我仍然无法缩放,我不确定我错过了什么

class mapViewController: UIViewController, UIScrollViewDelegate, IALocationManagerDelegate {

var imageViewBackground: UIImageView!

override func viewDidLoad() {


super.viewDidLoad()

let width = UIScreen.main.bounds.size.width
let height = UIScreen.main.bounds.size.height

let imageViewBackground = UIImageView(frame: CGRect(x:0, y:0, width:width-70, height:height-60))
var image: UIImage?
let urlString = "https://firebasestorage.googleapis.com/v0/b/coxur-59760.appspot.com/o/Maps%2FCapture.png?alt=media&token=741b1425-cb01-453b-8c40-47f6e5fd528d"

let url = NSURL(string: urlString)! as URL
if let imageData: NSData = NSData(contentsOf: url) {
image = UIImage(data: imageData as Data)
}
imageViewBackground.image = image

// you can change the content mode:
imageViewBackground.contentMode = UIView.ContentMode.scaleAspectFill

var scrollView: UIScrollView!
scrollView = UIScrollView(frame: CGRect(x: 0, y: 120, width: width, height: height))
scrollView.contentSize = CGSize(width: width, height: 2000)
scrollView.delegate = self
scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 6.0

scrollView.addSubview(imageViewBackground)
self.view.addSubview(scrollView)
//self.view.sendSubviewToBack(imageViewBackground)
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {

return imageViewBackground
}


}

我在这里做错了什么?

最佳答案

问题是这一行:

let imageViewBackground = UIImageView(frame: CGRect(x:0, y:0, width:width-70, height:height-60))

删除。问题解决了。

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

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