объявление < /p>
var preBView: UIView?
< /code>
Вот как я добавляю Swiftui в uikit view < /p>
let index = Int(prebuitType)
let swiftUIView = getPrebuiltView(index: index + 1 , width: self.viewStamp.frame.width, height: 200,objTemp: self.currentTemplate ?? TemplateModel())
preBView = createUIView(from: swiftUIView)
preBView!.translatesAutoresizingMaskIntoConstraints = false
self.viewStamp.addSubview(preBView!)
// Apply Constraints
NSLayoutConstraint.activate([
preBView!.topAnchor.constraint(equalTo: self.viewStamp.topAnchor),
preBView!.leadingAnchor.constraint(equalTo: self.viewStamp.leadingAnchor),
preBView!.trailingAnchor.constraint(equalTo: self.viewStamp.trailingAnchor),
preBView!.bottomAnchor.constraint(equalTo: self.viewStamp.bottomAnchor)
])
< /code>
if let _ = preBView {
preBView!.removeFromSuperview()
}
< /code>
But even after calling removeFromSuperview(), the view still appears on the screen and doesn't actually get removed.
preBView is not nil (I verified it's initialized).
I confirmed this code block is being executed.
preBView was previously added using viewStamp.addSubview(preBView).
Why isn’t preBView.removeFromSuperview() actually removing the view from the screen?
Подробнее здесь: https://stackoverflow.com/questions/795 ... efromsuper