See the Apple document excerpt below. If calling animation didMove(toParent:) is called after the transition not inside of the animation block, no animation the immediately after the addChild.
With animation
@objc func buttonAction(sender: UIButton!) {
guard let theButton = sender as? MyButton else { return}
UIView.transition(with: self.view, duration: 0.5, options: .transitionCurlDown, animations: { [self] in
self.addChild(setController)
self.view.addSubview(setController.view)
}, completion: {
setController.didMove(toParent: self)
})
}
No animation
@objc func buttonAction(sender: UIButton!) {
guard let theButton = sender as? MyButton else { return}
self.view.addSubview(setController.view)
self.addChild(setController)
setController.didMove(toParent: self)
}
Discussion
Your view controller can override this method when it wants to react to being added to a container.
If you are implementing your own container view controller, it must call the didMove(toParent:) method of the child view controller after the transition to the new controller is complete or, if there is no transition, immediately after calling the addChild(_:) method.
The removeFromParent() method automatically calls the didMove(toParent:) method of the child view controller after it removes the child.
Sundel:
https://www.swiftbysundell.com/basics/child-view-controllers/
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: