我看不到添加到 UIView 的 UIView subview 。我可以在 View 层次结构中清楚地看到它,但我在应用程序运行时看不到它。
代码:
var magnifyingView: UIView = {
let view = UIView()
view.alpha = 1.0
view.backgroundColor = UIColor.yellow
return view
}()
guard let cgImage = capturedImage else{return}
let image = UIImage.init(cgImage: cgImage, scale: 1.0, orientation: UIImage.Orientation.right)
imageView.image = image
self.addSubview(imageView)
bottomSection.addSubview(homeButton)
bottomSection.addSubview(retakeButton)
bottomSection.addSubview(continueButton)
self.addSubview(bottomSection)
showMagifyingView()
self.bringSubviewToFront(magnifyingView)
private func showMagifyingView(){
magnifyingView = UIView()
magnifyingView.frame = CGRect.init(x: 30, y: 30, width: 200, height: 200)
self.addSubview(magnifyingView)
magnifyingView.translatesAutoresizingMaskIntoConstraints = false
magnifyingView.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.3).isActive = true
magnifyingView.heightAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.3).isActive = true
magnifyingView.topAnchor.constraint(equalTo: self.topAnchor, constant: 30).isActive = true
magnifyingView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -30).isActive = true
}
View Heirarchy(蓝色突出显示的矩形 UIview 是我在运行时在我的应用程序上看不到的内容。即使它在那里并且我已将它放在前面)
最佳答案
在类的顶部初始化magnifyingView
var magnifyingView: UIView = {
let view = UIView()
view.alpha = 1.0
view.backgroundColor = UIColor.yellow
return view
}()
但是您要在 showMagifyingView()
中添加一个不同的 magnifyingView = UIView()
作为 subview 。
关于swift - 看不到 UIView 的 UIView subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58695196/