如果获取一个被旋转过的UIImageView的四个坐标?

agentgamer 发布于 2013年08月07日
无人欣赏。

其实这个UIImageView是可以被任意变换过的(translate, rotate, scale)当这些变换结束的时候怎样获取当前view的四角坐标? view.frame.origin 是变换后的原点,那其他3个坐标怎么拿?

在stackoverflow上有一个一模一样的问题,原理是用 CGPointApplyAffineTransform 来变换相应的点坐标,但是我不是很清楚他的代码,我自己试验了以后发现不行,求各路大神现身说法。。。

共3条回复
liues1992 回复于 2013年08月07日

首先一点: view.frame.origin并不是变换后的原点, 这一点在苹果的文档里面可以看到。

Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.

另外那个答案应该很清楚:先保存原来的四个点坐标。 进行矩阵变换后,用这个矩阵对四个点进行变换(使用CGPointApplyAffineTransform方法)得到变换后的坐标。

agentgamer 回复于 2013年08月08日

谢谢@liues1992 ,说的不错,变换后的origin更像是外接矩形的origin。 外接矩形可以通过 [self.view convertRect:view.frame fromeview:self.view]得到。

liues1992 回复于 2013年08月08日

No, 文档里说了frame是未定义的。 不代表任何东西

登录 或者 注册
相关帖子