简体   繁体   English

如何在旋转过程中获得图像上的角位置?

[英]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. 现在我想在图像旋转时获得ImageView角落左上角的位置。

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. 原始坐标是初始框架矩形的左上角,右上角,左下角和右下角。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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