如何获取 UIImageView 的 4 个坐标?
我知道可以得到CGRect以及origin.x和origin.y,但是如何找到所有4个角呢?
编辑:我正在旋转 UIImageViews,这就是我问的原因:P
最佳答案
您可以添加矩形的宽度和高度来获取其他 3 个点的坐标。
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来获取它们在你指定的变换下的变换坐标。
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);
//...
(注意:未经测试。)
关于iphone - 检索旋转的 UIImageView 的所有 4 个坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5530328/