Hey,
i am moving between 2 VCs using a button each and i have an animation when changing VC
Now when i disable the slideAnimator everything works fine and i can press each button infinite times.
But as soon as i "turn on" the slideAnimator, this happens:
i press the first button and the second VC opens up. Now i press the button on the second VC and the first VC shows up. So everything fine. But now the first button doesnt work anymore. Neither does it show the second VC, nor does the blue text turn black (which normally happens as long as the button is selected).
I think there should be an easy fix but so far i couldnt find anything helpful.
My code:
import UIKit
class ViewController: UIViewController {
let slideAnimator = SlideAnimator()
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destination = segue.destination
destination.transitioningDelegate = slideAnimator
}
}
with a slideAnimator class:
import UIKit
class SlideAnimator: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {
var duration = 0.5
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else {
return
}
guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else {
return
}
let container = transitionContext.containerView
let screenOffUp = CGAffineTransform(translationX: 0, y: -container.frame.height)
let screenOffDown = CGAffineTransform(translationX: 0, y: container.frame.height)
container.addSubview(fromView)
container.addSubview(toView)
toView.transform = screenOffUp
UIView.animate(withDuration: duration, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: [], animations: {
fromView.transform = screenOffDown
fromView.alpha = 0.5
toView.transform = CGAffineTransform.identity
toView.alpha = 1
}) { (success) in
transitionContext.completeTransition(success)
}
(i have added all buttons, etc. on the main.storyboard)
I´m thankful for any ideas!