gpt4 book ai didi

ios - 扩展图像上的捏合手势识别器

转载 作者:行者123 更新时间:2023-11-30 12:32:27 26 4
gpt4 key购买 nike

我已将点击手势识别器操作添加到我的 ImageView 中。点击图像后,它会扩展到全屏,然后再次点击时会关闭全屏。在图像已经展开后,如何添加捏合来缩放图像。这是我使图像全屏显示的代码。

//expand image


let newImageView: UIImageView!

@IBAction func imageTapped(_ sender: UITapGestureRecognizer)




{
let imageView = sender.view as! UIImageView

let scrollView = UIScrollView(frame: self.view.frame)


let newImageView = UIImageView(image: imageView.image)
newImageView.frame = self.view.frame
newImageView.backgroundColor = .black
newImageView.contentMode = .scaleAspectFit
newImageView.isUserInteractionEnabled = true


let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
scrollView.addGestureRecognizer(tap)


scrollView.delegate = self
scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 5.0

scrollView.addSubview(newImageView)

self.view.addSubview(scrollView)
}

func viewForZooming(in scrollView: UIScrollView) -> UIView?
{
return newImageView;
}

func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
sender.view?.removeFromSuperview()
}

最佳答案

当您想显示完整图像时,请使用 scrollview 代替 imageView

let newImageView: UIImageView!

@IBAction func imageTapped(_ sender: UITapGestureRecognizer)
{
let imageView = sender.view as! UIImageView

let scrollView = UIScrollView(frame: self.view.frame);

newImageView = UIImageView(image: imageView.image)
newImageView.frame = self.view.frame
newImageView.backgroundColor = .black
newImageView.contentMode = .scaleAspectFit
newImageView.isUserInteractionEnabled = true


let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
scrollView.addGestureRecognizer(tap)

scrollView.delegate = self
scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 5.0

scrollView.addSubview(newImageView)
self.view.addSubview(scrollView)
}

并记住viewForZooming委托(delegate)函数

 func viewForZooming(in scrollView: UIScrollView) -> UIView?
{
return newImageView;
}

关于ios - 扩展图像上的捏合手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43335981/

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