Let UIView go.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.