开发者

How to convert window coordinates relative to a specific view?

Example: I have a CGPoint in window coordinates:

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

There is aView whi开发者_高级运维ch has a superview in a superview in a superview. Somewhere deep in the view hierarchy, probably even transformed a few times.

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];


Perhaps you could iterate through the superview tree, drilling down to subviews by tag, and add or subtract the subview's frame.origin values to get to a translated windowPoint relative to the view-of-interest's frame.origin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜