Search code examples
swiftanimationcgaffinetransformdismissviewcontroller

Showing ViewController's View when animating upper ViewController


I have ViewController(1) presented over another ViewController(2), I want to accomplish the effect that when I dismiss viewController1 I perform a reduction of size through CGAffineTransform and I dismiss it.

The effect I want to accomplish though is that when I reduce the size of ViewController1's view I want to see also the view of ViewController2 behind it, while now I'm only seeing a black background.

The code I'm using is really simple:

UIView.animate(withDuration: 2, animations: {
        self.view.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
    }) { (_) in
        self.dismiss(animated: true, completion: nil)
    }

I don't know how to reach that effect


Solution

  • Make sure to set this presentation for the top animated vc

    vc.modalPresentationStyle = .overCurrentContext
    

    This will guarantee transparency behind when you change frame / transform the view of that top vc