0
votes

I am looking for an example of how to implement UIRotationGestureRecognizer of a UIImageView inside a UIScrollView, where the rotation is performed relative to where the touches occur, rather than relative to the origin of the UIImageView.

In most examples I've found, the ImageView is rotated around its own center point. In other words, if you place 2 fingers in the top left corner of the image, and twist them (to perform the rotation gesture), the UIImageView will rotate around its own origin.

The behaviour I'm looking for would have the UIImageView pivot around the touch points.

While there are plenty of tutorials on how to implement UIRotationGestureRecognizer for an ImageView inside a ScrollView, I haven't found any that describe how to perform a rotation that is relative to the touches.

1
Do you want the whole scroll view contents to rotate around the center of the touches, or just the image view that's in the scroll view?Duncan C

1 Answers

0
votes

A UIRotationGestureRecognizer returns an angle of rotation.

The base class, UIGestureRecognizer, has a method

location(ofTouch:in:) and a var numberOfTouches

In your valueChanged handler for your gesture recognizer you should be able to fetch the 2 touches, find the midpoint of those two points, and apply your rotation around that rather than the center of the view.