title: iOS Swift: Rotate and Scale UIView without resizing
body: <p>I have a UIView which i want to scale and rotate via pan and pinch gesture. But issue is when i scale view and after then when i rotate it's resizing back to initial value before scaling.</p>
  
  <pre><code>extension UIView {
  
      func addPinchGesture() {
          var pinchGesture = UIPinchGestureRecognizer()
          pinchGesture = UIPinchGestureRecognizer(target: self,
                                                  action: #selector(handlePinchGesture(_:)))
          self.addGestureRecognizer(pinchGesture)
      }
  
      @objc func handlePinchGesture(_ sender: UIPinchGestureRecognizer) {
          self.transform = self.transform.scaledBy(x: sender.scale, y: sender.scale)
          sender.scale = 1
      }
  
  }
  
  // ROTATION
  extension UIView {
  
      func addRotationGesture() {
          var rotationGesture = RotationGestureRecognizer()
          rotationGesture = RotationGestureRecognizer(target: self,
                                                      action: #selector(handleRotationGesture(_:)))
          self.addGestureRecognizer(rotationGesture)
      }
  
      @objc func handleRotationGesture(_ sender: RotationGestureRecognizer) {
          var originalRotation = CGFloat()
          switch sender.state {
          case .began:
              sender.rotation = sender.lastRotation
              originalRotation = sender.rotation
          case .changed:
              let newRotation = sender.rotation + originalRotation
              self.transform = CGAffineTransform(rotationAngle: newRotation) // Rotation is fine but it is resizing view
  //            self.transform = self.transform.rotated(by: newRotation / CGFloat(180 * Double.pi)) // NOT WORKING i.e. irregular rotation
          case .ended:
              sender.lastRotation = sender.rotation
          default:
              break
          }
      }
  
  }
  </code></pre>
  
  <h3>Before Scaling</h3>
  
  <p><a href="https://i.stack.imgur.com/uoadi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uoadi.jpg" alt="enter image description here"></a></p>
  
  <h3>After Scaling</h3>
  
  <p><a href="https://i.stack.imgur.com/bEFT4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bEFT4.jpg" alt="enter image description here"></a></p>
  
  <h3>After Rotation</h3>
  
  <p><a href="https://i.stack.imgur.com/oYJ9A.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oYJ9A.jpg" alt="enter image description here"></a></p>
  
  <p>I want it to be rotate without affecting view size. How can i achieve that?</p>