Want to implement a feature that rotates a picture around a center point. Using uipangesturerecognizer gestures to achieve one, by calculating the position of gesture movement, calculate the offset of the center point of the finger from the picture, and then let the Uiimageview offset the same degree. Test, found that although the picture is rotated, but the center point seems to have been changing, the coordinates of the center point is printed without change, it is possible that the picture is square, the next time with a circular picture to try.
Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (Panview:)];[ _imageview addgesturerecognizer:pan];-(void) Panview: (uitapgesturerecognizer*) pan { Cgaffinetransform Starttransform; Cgpoint point = [Pan LocationInView:self.view]; NSLog (@ ' point =%@ ', Nsstringfromcgpoint (point)); Calculate deflection angle of float Deflectionangle = atan2 (POINT.Y-_IMAGEVIEW.FRAME.ORIGIN.Y, point.x-_imageview.frame.origin.x); Switch (pan.state) {case Uigesturerecognizerstatebegan: starttransform = _imageview.transform; break; Case uigesturerecognizerstatechanged: _imageview.transform = Cgaffinetransformrotate (Starttransform, Deflectionangle); break; Case uigesturerecognizerstateended: Break ; Default: Break ; }}
Let UIView go.