ios - 在 UIViewImage 上添加 UIView。用户可以缩放图像
问题描述
我试图在我的 UIImage 上添加 UIView。但这对我不起作用。当我减少和增加我的图像时,UIView 向下移动并且没有完全覆盖我的图像。
我使用双击进行缩放。
@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)
}
}
我尝试使用这些代码,但它对我不起作用。
第一的:
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)
第二:
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), ])
另外,我尝试添加情节提要,但它对我也不起作用。有没有人有想法或建议?
解决方案
尝试将 UIView 添加到 viewController 而不是 UIImageView 的主视图,并为 imageView 设置约束
推荐阅读
- c++ - QTextEdit 中的“选择”和“光标”有什么区别?
- r - 在 R 中绘制数据;错误:未为类型“列表”实现默认方法
- python - Eve + 带有特殊字符的 MongoDB
- mysql - 通过 Matlab 与 MySQL 数据库的操作系统无关连接
- powershell - 无法通过 PowerShell 从 FolderBrowserDialog 创建新文件夹
- reactjs - 从子端进行子组件和父组件之间通信的最佳实践是什么?
- android - 运行 adb 时出错:找不到 Android 设备 - expo-cli linux
- spring-boot - 使用profile打包部署spring boot项目成war成功,但是尝试访问页面时无法访问页面
- kivy - Kivy RecycleView:我们如何滚动到列表的末尾
- python - 如何使用 Reddit API 在我的 HTML 文件中呈现图像