Reputation: 502
How can I make a fade animation from one View controller to the next. So basically what I want is when I click a button, it fades from the current view controller to the one it's linked to. Is there a way to do this. I've been searching for a while and haven't been able to find anything in Swift. Thank you for the help!
Upvotes: 1
Views: 4415
Reputation: 502
Here is my answer. Instead of making every scene a different ViewController, I just made every scene an SKScene and used one ViewController for the entire project. Now, to get from one scene to another I used this:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch: AnyObject in touches {
// Get the location of the touch in this scene
let location = touch.location(in: self)
// Check if the location of the touch is within the button's bound
if L1.contains(location) {
let gameScene = GameScene()
gameScene.scaleMode = .resizeFill
gameScene.view?.ignoresSiblingOrder = true
let transition = SKTransition.fade(withDuration: 1)
self.scene?.view?.presentScene(gameScene, transition: transition)
print("tapped!")
}
}
This allowed me to use the line "self.scene?.view?.presentScene(gameScene, transition: transition" to achieve this transition. The reason I transferred over from view controllers was not only for the animations but also to make the app more efficient and to have it work better and be smoother.
Upvotes: 0
Reputation: 2640
let transition: CATransition = CATransition()
transition.duration = 0.4
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionFade
self.navigationController!.view.layer.addAnimation(transition, forKey: nil)
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("vcID") as! My_ViewController
self.navigationController?.pushViewController(vc, animated: false)
Upvotes: 5