如何转换相对于特定视图的窗口坐标? [英] How to convert window coordinates relative to a specific view?

查看:253
本文介绍了如何转换相对于特定视图的窗口坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:我在窗口坐标中有一个CGPoint:

Example: I have a CGPoint in window coordinates:

CGPoint windowPoint = CGPointMake(220.0f, 400.0f);

aView 其中包含superview超级视图中的超级视图。在视图层次结构深处的某个地方,甚至可能转换了几次。

There is aView which has a superview in a superview in a superview. Somewhere deep in the view hierarchy, probably even transformed a few times.

当你得到一个UITouch时,可以要求它为-locationInView:它会返回相对的坐标那个观点。

When you get a UITouch, you can ask it for -locationInView: and it will return the coordinates relative to that view.

我需要几乎一样的东西。有没有一种简单的方法可以实现这一目标?

I need pretty much the same thing. Is there an easy way to accomplish that?

推荐答案

我找到了一个非常简单的解决方案:

I found a really easy solution:

[self.aView convertPoint:windowPoint fromView:self.window];

这篇关于如何转换相对于特定视图的窗口坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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