title: How animate UIView height constraint in Swift programmatically without making an IBOutlet?
body: <p>I have created a button which is attached to the top, leading and trailing and has fixed height. And when I'm tapping the button the new UIView instance should appear with animation. </p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
  var topButton = UIButton()
  var myView = UIView()
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      topButton = UIButton(type: .roundedRect)
      topButton.setTitle("Add Acctivity", for: .normal)
      topButton.backgroundColor = UIColor.purple
      topButton.setTitleColor(UIColor.white, for: .normal)
      topButton.titleLabel?.font = UIFont(name: "System", size: 26)
      topButton.translatesAutoresizingMaskIntoConstraints = false
      topButton.addTarget(self, action: #selector(expandMenu), for: .touchUpInside)
      view.addSubview(topButton)
  
      topButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
      topButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
      topButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
      topButton.heightAnchor.constraint(equalToConstant: 70).isActive = true
  
      myView.backgroundColor = UIColor.blue
      myView.translatesAutoresizingMaskIntoConstraints = false
      view.addSubview(myView)
      myView.topAnchor.constraint(equalTo: view.topAnchor, constant: 70).isActive = true
      myView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
      myView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
      myView.heightAnchor.constraint(equalToConstant: 100).isActive = true
  
  }
  
  @objc func expandMenu() {
  
     myView.heightAnchor.constraint(equalToConstant: 300).isActive = true
  
      UIView.animate(withDuration: 1) {
  
          self.view.layoutIfNeeded()
      }
  }
  
  
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/E7xA2.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E7xA2.gif" alt="Nothing is working even I put the height to be 300"></a></p>
  
  <p>And the interesting thing is when I'm putting the height smaller than its initial value the animation works.</p>
  
  <p><a href="https://i.stack.imgur.com/VVuIR.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VVuIR.gif" alt="enter image description here"></a></p>
  
  <p>I saw many tutorials when people are creating IBOutlet from storyboard and then changing its constant value. But I'm wondering how to do that programmatically.</p>