Here is a complete Rotate Gesture example: We have 2 things – a handle and the gesture itself that uses the handle.. Here is the gesture:
1 2 3 4 5 |
func createRotateGestureRecognizer(targetView:UIImageView) { var rotateGesture = UIRotationGestureRecognizer(target: self, action: ("handleRotate:")) targetView.addGestureRecognizer(rotateGesture) rotateGesture.delegate = self } |
1 |
("handleRotate:") |
is what points to the Handle ( make sure you don’t misspell this).
Here is the actual handle:
1 2 3 4 5 6 7 8 9 10 11 |
func handleRotate(recognizer : UIRotationGestureRecognizer) { recognizer.view!.transform = CGAffineTransformRotate(recognizer.view!.transform, recognizer.rotation) recognizer.rotation = 0 var label = recognizer.view as UIImageView // creating a new UIImageView out of the rotation if recognizer.state == UIGestureRecognizerState.Changed { hoverShadow(label) // add some Extra Shadow when we are rotating the new ImageView } else { shadow(label) // return to the original Shadow when not moving } } |