0

I am trying to use a custom transition to a full screen custom camera. When I do so using a slow fade animation it after completing the animation turns black.

The camera which at the beginning of the animation seems to work, suddenly goes away leaving behind the black background.

How can I make the transition work correctly?

Code:

mainVC:

@objc func buttonUp(_ sender: UIButton) {

    toCam.transform = CGAffineTransform.identity.scaledBy(x: 1, y: 1)
    toCam.backgroundColor = .yellow

    segue()
}

func segue() {
    performSegue(withIdentifier: "GoToCam", sender: self)
}

Custom segue class:

class goToCamAnimCustom: UIStoryboardSegue {

    override func perform() {
        scale()
    }

    func scale() {

        guard let destinationView = self.destination.view else {
            // Fallback to no fading
            self.source.present(self.destination, animated: false, completion: nil)
            return
        }

        destinationView.alpha = 0
        self.source.view?.addSubview(destinationView)

        UIView.animate(withDuration: CATransaction.animationDuration(), animations: {
            destinationView.alpha = 0.5
        }, completion: { _ in
            self.source.present(self.destination, animated: false, completion: nil)
        })

    }
}
Olympiloutre
  • 2,268
  • 3
  • 28
  • 38
  • 1
    can you also add what you have in destination view controller? more specifically viewDidLoad, viewWillAppear, viewWillDisapperar and etc? – m1sh0 Jul 16 '19 at 06:12
  • 2
    I tried this out and it doesn't seem the issue is segue-related (you do realize you set your target VC's view opacity to 0.5, right?). It's weird that you don't remove the view again from the source's view hierarchy (but in my test it's gone when I go back, maybe I missed sth). Usually you'd do that. Anyway, I guess the issue is related to how you set up the camera view, i.e. other code. Regardless, I'd *strongly* discourage from using a custom segue for this animation and recommend using a custom UIViewControllerTransitioningDelegate, see e.g. https://stackoverflow.com/a/26088001/710041. – Gero Jul 16 '19 at 09:10

0 Answers0