Slide 47
Slide 47 text
© ZOZO Technologies, Inc.
47
private var scnView: SCNView?
private var favParticle: SCNParticleSystem?
override func viewDidLoad() {
super.viewDidLoad()
guard let scene = SCNScene(named: "fav.scn", inDirectory: "./") else { return }
let node: SCNNode = scene.rootNode.childNode(withName: "particles", recursively: true)
favParticle = node.particleSystems?.first
}
private func addFavParticle() {
let scene = SCNScene()
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 10)
scene.rootNode.addChildNode(cameraNode)
scene.rootNode.addParticleSystem(favParticle)
scnView = SCNView(frame: view.bounds)
view.insertSubview(scnView!, belowSubview: favButton)
scnView?.scene = scene
}
@IBAction private func favButtonTapped() {
addFavParticle()
UIView.animate(withDuration: 0.6) { [weak self] in
self?.scnView!.alpha = 0
} completion: { [weak self] _ in
self?.scnView?.removeFromSuperview()
self?.scnView = nil
}
}