检索旋转的UIImageView的所有4个坐标 [英] Retrieving all 4 coordinates of a rotated UIImageView

查看:53
本文介绍了检索旋转的UIImageView的所有4个坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取UIImageView的4个坐标?

How does one get the 4 coordinates for a UIImageView?

我知道可以获取CGRect以及origin.x和origin.y,但是如何找到所有4个角?

I know the CGRect can be obtained and the origin.x and origin.y, but how can all 4 corners be found?

我正在旋转UIImageViews,这就是为什么我问:P

I am rotating the UIImageViews, thats why I asked :P

推荐答案

您可以添加矩形的宽度和高度以获取其他3个点的坐标.

You could add width and height of the rectangle to get the coordinates of the other 3 points.

CGRect rect = view.bounds;

CGPoint topLeft = rect.origin;
CGPoint topRight = CGPointMake(rect.origin.x + rect.size.width, rect.origin.y);
CGPoint bottomLeft =CGPointMake(rect.origin.x, rect.origin.y + rect.size.height);
CGPoint bottomRight = CGPointMake(rect.origin.x + rect.size.width,
                                  rect.origin.y + rect.size.height);

然后,您可以使用CGPointApplyAffineTransform获取指定变换下它们的变换坐标.

Then you could use CGPointApplyAffineTransform to get the transformed coordinates of them under your specified transform.

CGPoint center = view.center;
CGAffineTransform transf = CGAffineTransformMakeTranslation(-rect.size.width/2,
                                                            -rect.size.height/2);
transf = CGAffineTransformConcat(transf, view.transform);
transf = CGAffineTransformTranslate(transf, center.x, center.y);

topLeft = CGPointApplyAffineTransform(topLeft, transf);
//...

(注意:未经测试.)

这篇关于检索旋转的UIImageView的所有4个坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆