title: Remove constraints iOS
body: <p>I try to remove constraints. I want to different constraints on portrait and landscape. If I change the orientation to Portrait I call the function <strong>setupConstrainsInPortrait</strong> and conversely. I have two functions.</p>
  
  <p>This function setup Portrait mode.</p>
  
  <pre><code>func setupConstrainsInPortrait() {
  
      view.addSubview(myView)
  
      myView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
      myView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50).isActive = true
      myView.heightAnchor.constraint(equalToConstant: 300).isActive = true
      myView.widthAnchor.constraint(equalToConstant: view.frame.size.width).isActive = true
  
      view.addSubview(switchKmM)
  
      switchKmM.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
      switchKmM.topAnchor.constraint(equalTo: myView.bottomAnchor, constant: 10).isActive = true
      switchKmM.heightAnchor.constraint(equalToConstant: 50).isActive = true
      switchKmM.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
  
      view.addSubview(speedLbl)
  
      speedLbl.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
      speedLbl.topAnchor.constraint(equalTo: view.bottomAnchor, constant: -50).isActive = true
      speedLbl.heightAnchor.constraint(equalToConstant: 50).isActive = true
      speedLbl.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
  
  }
  </code></pre>
  
  <p>This function setup landscape mode.</p>
  
  <pre><code>    func setupConstrainsInLandScape() {
      view.addSubview(myView)
  
      myView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10).isActive = true
      myView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
      myView.heightAnchor.constraint(equalToConstant: 300).isActive = true
      myView.widthAnchor.constraint(equalToConstant: 150).isActive = true
  
      view.addSubview(switchKmM)
  
      switchKmM.leftAnchor.constraint(equalTo: myView.rightAnchor, constant: 30).isActive = true
      switchKmM.topAnchor.constraint(equalTo: view.topAnchor, constant: 30).isActive = true
      switchKmM.heightAnchor.constraint(equalToConstant: 50).isActive = true
      switchKmM.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
  }
  </code></pre>
  
  <p>I use these functions in viewWillTransition</p>
  
  <pre><code>override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
      if UIDevice.current.orientation.isLandscape {
          print("landscape!")
          view.backgroundColor = .green
          setupConstrainsInLandScape()
          self.viewWillLayoutSubviews()
  
  
      }
      else {
          print("portrét")
          view.backgroundColor = .white
          setupConstrainsInPortrait()
          self.viewWillLayoutSubviews()
  
      }
      super.viewWillTransition(to: size, with: coordinator)
  }
  </code></pre>
  
  <p>The problem is, that constraints(from portrait function) in landscape mode aren't deleted</p>
  
  <p>I hope that someone can help me... Thank you</p>