title: Making an animation to slide and hide/show an UIView(swift 5)
body: <p>I want to add animation to these two views.</p>
  
  <ol>
  <li>Red <code>UIView</code></li>
  <li>Green <code>UIView</code></li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/ChuWo.png" rel="nofollow noreferrer">My storyboard look like this</a></p>
  
  <p>From the picture I want to add an animation when click on these two views.</p>
  
  <p>First start with hide red <code>UIView</code>.</p>
  
  <p>Action : 1</p>
  
  <p><a href="https://i.stack.imgur.com/3cKCf.png" rel="nofollow noreferrer">when i click on green view i want green uiview silde to the right side until it disappear</a></p>
  
  <p>and the red <code>UIView</code> will slide out from the right side immediately.</p>
  
  <p><a href="https://i.stack.imgur.com/Pn3Yw.png" rel="nofollow noreferrer">red uiview slide from right side</a></p>
  
  <p>and stopp when it is at that point in the storyboard and hide green <code>UIView</code>.</p>
  
  <p>Action : 2</p>
  
  <p>and when i click on red view i want it to slide right until it disappears. Show green <code>UIView</code> and comes out from the right corner as well and hide red <code>UIView</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/ZyJWa.png" rel="nofollow noreferrer">red UIView slide out</a></p>
  
  <p>My Code</p>
  
  <pre><code>import UIKit
  
  class TestViewCell: UICollectionViewCell {
  
      @IBOutlet weak var bgView: UIView!
  
      @IBOutlet weak var bgAlertView: UIView!
      @IBOutlet weak var imgAlert: UIImageView!
  
      @IBOutlet weak var bgAlreadyAlertView: UIView!
      @IBOutlet weak var imgAlreadyAlert: UIImageView!
  
      override func awakeFromNib() {
          super.awakeFromNib()
  
          //Make an action when tap on bgAlertView
          let actionBgAlert : Selector = #selector(self.actionBgAlert)
          let viewPostsViewGesture = UITapGestureRecognizer(target: self, action: actionBgAlert)
          bgAlertView.isUserInteractionEnabled = true
          bgAlertView.addGestureRecognizer(viewPostsViewGesture)
  
          //Make an action when tap on bgAlreadyAlertView
          let actionBgAlreadyAlert : Selector = #selector(self.actionBgAlreadyAlert)
          let viewAlreadyViewGesture = UITapGestureRecognizer(target: self, action: actionBgAlreadyAlert)
          bgAlreadyAlertView.isUserInteractionEnabled = true
          bgAlreadyAlertView.addGestureRecognizer(viewAlreadyViewGesture)
  
      }
  
      //action1
      @objc func actionBgAlert(sender: UITapGestureRecognizer){
  
          if imgAlert.image == #imageLiteral(resourceName: "alarm") {
  
              self.bgAlertView.isHidden = true
              self.bgAlreadyAlertView.isHidden = false 
  
      }
  
      //action2
      @objc func actionBgAlreadyAlert(sender: UITapGestureRecognizer){
  
          if imgAlreadyAlert.image == #imageLiteral(resourceName: "alarmedMain") {
  
              self.bgAlertView.isHidden = false
              self.bgAlreadyAlertView.isHidden = true 
  
      }
  
  }
  </code></pre>