2

Exist in SwiftUI the equivalent of following UIKit methods?

view.addSubview(aView)
view.removeFromSuperview()
view.bringSubviewToFront(aView)
view.sendSubviewToBack(aView)

Basically, I need to remove myView from oldSuperView, add it to newSuperView and bring to the front a childView already present in newSuperView

1 Answer 1

4

No equivalent. Because every time you change a state, the view is build again entirely. You can use if/else or etc to hide/show or even add or not add a view, but you can't add or remove without refreshing the view.

One thing you can do is to encapsulate the view you want to add or remove it's subviews and change it's state instead of it's superview. So changes will apply internally.

Sign up to request clarification or add additional context in comments.

1 Comment

I need something like tabview content, they can keep scroll state so that onAppear will be trigger. Do you know how to do that? I am using zindex but could not trigger onAppear event and scroll state

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.