ios - 从另一个类访问图像
问题描述
我有一个快速的问题。我正在尝试从另一个视图控制器设置图像。我究竟做错了什么?
主视图控制器:
//我如何设置弹出视图:
lazy var popUpView: PopViews = {
let view = PopViews()
view.translatesAutoresizingMaskIntoConstraints = false
view.layer.cornerRadius = 24
view.delegate = self
return view
}()
弹出视图的调用
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()){
self.handleShowPop()
}
handleShowPop 函数:
@objc func handleShowPop(){
view.addSubview(popUpView)
let image: UIImage = UIImage(named: "Test")!
popUpView.imageView = UIImageView(image: image)
popUpView.button.setTitle("View Our Menu2", for: .normal)
popUpView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -40).isActive = true
popUpView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
popUpView.heightAnchor.constraint(equalToConstant: view.frame.width - 154).isActive = true
popUpView.widthAnchor.constraint(equalToConstant: view.frame.width - 104).isActive = true
popUpView.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
popUpView.alpha = 0
UIView.animate(withDuration: 0.5){
self.visualEffectView.alpha = 0.7
self.popUpView.alpha = 1
self.popUpView.transform = CGAffineTransform.identity
}
}
这是 PopViews 类:
我可以在此处添加图像,但无法从第一个视图控制器访问它
class PopViews: UIView {
var imageView: UIImageView = {
let img = UIImageView(image: #imageLiteral(resourceName: "test"))
img.translatesAutoresizingMaskIntoConstraints = false
img.heightAnchor.constraint(equalToConstant: 80).isActive = true
img.widthAnchor.constraint(equalToConstant: 80).isActive = true
img.image = imgz
return img
}()
}
解决方案
推荐阅读
- apache - 无法在端口:80 上运行 httpd 时重新启动 Apache
- python - Scrapy:AttributeError:'str'对象没有属性'setdefault'
- java - 将项目添加到在另一个活动中使用 baseAdapter 的 listView
- elasticsearch - Elasticsearch docker容器在启动时挂起而没有错误
- ios - 使用 PageController swift 移动到下一个 ViewMontroller
- python - 将 Gtk.Widget 放在带有顶部填充的 Box 中
- javascript - 单击时如何更改表格中的单元格值?
- python - ParseError:未找到元素:第 1 行,第 0 列
- javascript - 所有 Datepicker 和 Datecontrol 都不能在 activeForm Kartik 中工作
- javascript - 无法在文件上传表单与本地主机路由 (JavaScript) 之间建立连接