Complete the code to add a pan gesture recognizer to the view.
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan)) view.[1](panGesture)
To detect drag gestures, you add a UIPanGestureRecognizer to the view using addGestureRecognizer.
Complete the code to get the translation point from the pan gesture recognizer.
let translation = sender.[1](in: view)
The translation(in:) method gives the drag distance of the gesture in the view's coordinate system.
Fix the error in the magnification gesture handler to get the scale value.
func handlePinch(_ sender: UIPinchGestureRecognizer) {
let scale = sender.[1]
view.transform = view.transform.scaledBy(x: scale, y: scale)
sender.scale = 1.0
}The scale property of UIPinchGestureRecognizer gives the pinch scale factor.
Fill both blanks to get the rotation angle and apply it to the view transform.
func handleRotation(_ sender: UIRotationGestureRecognizer) {
let rotation = sender.[1]
view.transform = view.transform.[2](by: rotation)
sender.rotation = 0
}The rotation property gives the rotation angle. The rotated(by:) method applies rotation to the transform.
Fill all three blanks to reset the view transform after gestures.
func resetTransform() {
UIView.animate(withDuration: [1]) {
self.view.transform = CGAffineTransform.[2]()
} completion: { _ in
print("Transform [3]")
}
}Animation duration is 0.5 seconds. CGAffineTransform.identity() resets the transform. The print statement confirms the reset.