我有一个使用CAEmitterLayer
. 粒子效果创建五彩纸屑效果,其中五彩纸屑从视图顶部落下。被CAEmitterLayer
作为子层添加到视图控制器的UIView
(专门为此目的在情节提要中创建的confettiView
)中:viewDidLoad()
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)
}
当UIViewController
包含UIView
使用以下自定义代码(通过将其添加到另一个UIViewController
)显示时,效果会正确显示。
parentViewController.addChildViewController(childViewController)
childViewController.frame = parentViewController.view.frame
parentViewController.view.addSubview(childViewController.view)
childViewController.didMove(toParentViewController: parentViewController)
但是,当我将视图更改为模态显示(使用UIViewController.present
)时,效果不可见:
parentViewController.present(childViewController, animated: true)
当视图控制器模态呈现时如何使粒子效果可见的任何见解?