gpt4 book ai didi

ios - 在 UIView 图像上添加 UIView。用户可以缩放图像

转载 作者:行者123 更新时间:2023-11-30 11:23:49 25 4
gpt4 key购买 nike

我尝试在 UIImage 上添加 UIView。但这对我不起作用。当我缩小和增加图像时,UIView 向下移动并且没有完全覆盖我的图像。 enter image description here

我使用双击进行缩放。

@objc func doubleTap(gestureRecognizer: UITapGestureRecognizer) {

if self.productScrollView.zoomScale == 1 {
self.productScrollView.zoom(to: self.zoomRectForScale(scale: self.productScrollView.maximumZoomScale, center: gestureRecognizer.location(in: gestureRecognizer.view)), animated: true)
} else {
self.productScrollView.setZoomScale(1, animated: true)
}

}

我尝试使用这些代码,但它对我不起作用。

  1. 第一:

     let tintView = UIView()
    tintView.backgroundColor = UIColor(white: 0, alpha: 0.5)
    tintView.frame = CGRect(x: 0, y: 0, width: imageView.frame.width,
    height: imageView.frame.height)
    imageView.addSubview(tintView)
  2. 第二:

    let tintView = UIView()
    tintView.backgroundColor = UIColor(white: 0, alpha: 0.5)
    tintView.translatesAutoresizingMaskIntoConstraints = false
    imageView.addSubview(tintView)
    NSLayoutConstraint.activate([
    tintView.bottomAnchor.constraint(equalTo: imageView.bottomAnchor),
    tintView.leadingAnchor.constraint(equalTo: imageView.leadingAnchor),
    tintView.trailingAnchor.constraint(equalTo: imageView.trailingAnchor),
    tintView.topAnchor.constraint(equalTo: imageView.topAnchor),
    ])

另外,我尝试添加 Storyboard,但它对我来说也不起作用。有人有想法或建议吗?

最佳答案

尝试将 UIView 添加到 viewController 的主视图而不是 UIImageView 并为 imageView 设置约束

关于ios - 在 UIView 图像上添加 UIView。用户可以缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50976210/

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