I have a particle system created with a CAEmitterLayer
. The particle effect creates a confetti effect where confetti drops down from the top of the view. The CAEmitterLayer
is added as a sublayer to an UIView
(specifically created for that purpose in a storyboard, the confettiView
) in viewDidLoad()
for the view controller:
override func viewDidLoad() {
...
createParticles(for: confettiView)
...
}
func createParticles(for view: UIView) {
let particleEmitter = CAEmitterLayer()
particleEmitter.emitterPosition = CGPoint(x: view.center.x, y: -96)
particleEmitter.emitterShape = kCAEmitterLayerLine
particleEmitter.emitterSize = CGSize(width: view.frame.size.width, height: 1)
...
(adding the emitter cells here)
...
view.layer.addSublayer(particleEmitter)
}
When the UIViewController
including the UIView
is displayed with the following custom code (by adding it to another UIViewController
) the effect is displayed correctly.
parentViewController.addChildViewController(childViewController)
childViewController.frame = parentViewController.view.frame
parentViewController.view.addSubview(childViewController.view)
childViewController.didMove(toParentViewController: parentViewController)
But when I change the view to be presented modally (with UIViewController.present
), the effect is not visible:
parentViewController.present(childViewController, animated: true)
Any insights on how to make the particle effect visible when the view controller is presented modally?