title: View moves weirdly on rotation through pan gesture
body: <p>I have a pan gesture on a button that moves the button in the direction of the pan. When the translation is "far enough" the button gets rotated. On this rotation the button visible goes to its initial position or close and then back where it should be. Cannot figure out what is going on. This is my code:</p>
  
  <pre><code>    @IBAction func didPanButton(_ sender: UIPanGestureRecognizer) {
  
      print("Did pan button", sender.translation(in: sender.view).x)
  
      answerButton.center.x = view.center.x + sender.translation(in: sender.view).x
  
      switch buttonPosition {
      case .left:
          print("Rotate button left")
          UIView.animate(withDuration: 0.5, animations: {
              self.rotateButtonLeft()
          })
      case .right:
          print("Rotate button right")
          UIView.animate(withDuration: 0.5, animations: {
              self.rotateButtonRight()
          })
      case .middle:
          print("Remove button rotation")
          UIView.animate(withDuration: 0.5, animations: {
              self.removeButtonRotation()
          })
      }
  
  } 
  
  var buttonPosition : ButtonPosition {
      let leftWidth = (view.frame.size.width - answerButton.frame.size.width) / 2
  
      if answerButton.frame.origin.x &lt; leftWidth / 2 {
          return .left
      }
  
      if answerButton.frame.origin.x &gt; leftWidth * 3 / 2 {
          return .right
      }
  
      return .middle
  }
  
  func rotateButtonLeft() {
      let degrees : CGFloat = -10; //the value in degrees
      answerButton.transform = CGAffineTransform(rotationAngle: degrees * CGFloat.pi/180);
      let image = UIImage(named: "item_no")
      answerButton.setImage(image, for: UIControlState.normal)
  }
  
  func rotateButtonRight() {
      let degrees : CGFloat = 10; //the value in degrees
      answerButton.transform = CGAffineTransform(rotationAngle: degrees * CGFloat.pi/180);
      let image = UIImage(named: "item_yes")
      answerButton.setImage(image, for: UIControlState.normal)
  }
  
  func removeButtonRotation() {
      let degrees : CGFloat = 0; //the value in degrees
      answerButton.transform = CGAffineTransform(rotationAngle: degrees * CGFloat.pi/180);
      let image = UIImage(named: "item_neutral")
      answerButton.setImage(image, for: UIControlState.normal)
  }
  </code></pre>