简体   繁体   中英

How to get corner position on an image during rotation?

I'm using this code to rotate image :

if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded)
{
    currentrotation += lastRotation;
    lastRotation = 0.0;
    return;
}


    CGFloat rotation =  0.0 - (lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);
    CGAffineTransform currentTransform = imgComment.transform;
    CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);
    [imgComment setTransform:newTransform];

    lastRotation = [(UIRotationGestureRecognizer*)sender rotation];

Can't get position of image view when it rotates.

Now I want to get position of top-left side of the corner of ImageView when image rotates.

Please Help !!

You will need to get the coordinates of the individual corners by applying a transformation. The frame of the rooted view will be the smallest possible rectangle that encloses the view. To get the rotated coordinate of a point use:

CGPoint transformedPoint = CGPointApplyAffineTransform(originalCoordinate, transform);

The original coordinates are top-left, top-right, bottom-left and bottom-right of your initial frame rectangle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM