iOS_Animations_by_Tutorials_v4.0.1 Chapter 3

override func viewDidAppear(_ animated: Bool) {
       super.viewDidAppear(animated)
        // create new view
        let newView = UIImageView(image: UIImage(named: "banner"))
        newView.center = animationContainerView.center
        
        // add the enw view via transition
        UIView.transition(with: animationContainerView,
                          duration: 0.33,
                          options: [.curveEaseOut, .transitionFlipFromBottom],
                          animations: {
                            self.animationContainerView.addSubview(newView)
        }, completion: nil)

create a new view named newView in viewDidAppear, ‘newView’ is a local variable, why ‘newView’ is global variable when removing ?

//remove the view via transition

   UIView.transition(with: animationContainerView, duration: 0.33, 
        options: [.curveEaseOut, .transitionFlipFromBottom],  
        animations: {
            self.newView.removeFromSuperview()
    }, completion: nil)

@viho Both code snippets are from the theoretical part of the chapter. They are independent, so the local newView that you add in viewDidAppear(_:) doesn’t have anything to do with the global newView that you remove.

Please let me know if you have any other questions or issues about the whole thing. Thank you!

This topic was automatically closed after 166 days. New replies are no longer allowed.