2017-06-15 93 views
1

我找到一个类似的问题here,当我翻译我的视图,我可以成功地解决这个问题,但是当我旋转或缩放我的视图时,我得到了不正确的结果。任何人都可以帮助我?如何检索旋转缩放翻译UIView的所有4个坐标?

+0

什么你的结果是?显示你的输出。和你想要的是什么。 –

+0

@elk_cloner [这是我的演示网址](https://github.com/sunwell/Demo/tree/master/CoreAnimationDemo)和[这是视频](https://github.com/sunwell/Demo/blob /master/CoreAnimationDemo/CoreAnimationDemo/test.mp4) – Cr02y

回答

2

我找到了演示解决方案,并且已经过测试。你可以使用代码从本期的接受的答案:Find Frame Coordinates After UIView Transform is Applied (CGAffineTransform)

使用上面的代码作为一个UIView的类别,然后得到这样的地步:

topleft = [view newTopLeft]; 
topright = [view newTopRight]; 
bottomleft = [view newBottomLeft]; 
bottomright = [view newBottomRight]; 

结果是:enter image description here

+0

也许我没有把问题弄清楚。就我而言,视图可以以任何角度旋转。实际上,旋转后,视图的原点不是左上角的坐标。 [这是我的演示网址](https://github.com/sunwell/Demo/tree/master/CoreAnimationDemo)和[这是视频](https://github.com/sunwell/Demo/blob/ master/CoreAnimationDemo/CoreAnimationDemo/test.mp4) – Cr02y

+0

@BirdV,好的,我下载你的demo,稍后给你回应。 –

+0

有四个红色的点记录矩形的四个角的坐标。我想看到的是,当我旋转或缩放绿色矩形后,四个红色点仍然在矩形的角落。因此,我可以使用这四个红点来检查该矩形是否超出较大的矩形范围(红线矩形)。 – Cr02y