iphone - 检索旋转的 UIImageView 的所有 4 个坐标

标签 iphone cocoa-touch

如何获取 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/

相关文章:

iphone - 在 iPhone 中返回上一个屏幕

ios - 更新 MPRemoteCommandCenter 播放/暂停按钮

ios - Objective-C/Cocoa 中 Java 的 Thread.sleep() 等价物是什么?

iphone - 如何判断 UIView 是否可见并显示在屏幕上?

iphone - 如何录制/保存iPhone应用程序中正在播放的音频?

iphone - 开发分布式 iPhone/iPad 应用程序的框架建议

iphone - WEPopoverController PresentPopoverFromBarButtonItem 导致指定的 UIBarButtonItem 消失

iphone - OpenGL ES 2.0 : Object rotation problem

iphone - iPad/iPhone 请停止解析我网站上的电话号码

cocoa-touch - 对象 A 如何等待对象 B 在其 Core Location Delegate 中完成获取位置数据,以便它可以使用该数据?