在 UIScrollView 绝对屏幕位置内获取 UIButton [英] get UIButton inside an UIScrollView absolute screen location

查看:37
本文介绍了在 UIScrollView 绝对屏幕位置内获取 UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我找不到答案......

It may be a dumb question, but I can't find an answer to this ...

我有一个 UIScrollView 和一些 UIButtons.当我按下按钮时,我想知道按钮的屏幕位置.如果我使用 button.frame 它会给我 UIScrollView 中的位置,这是正常的.

I have an UIScrollView and inside a number of UIButtons. When I press a button, I want to know the screen location of the button. If I use button.frame it gives me the position inside UIScrollView, which is normal.

如何找到相对于按下按钮的屏幕的 x 和 y?

How can I find x and y relative to screen of the button pressed?

提前致谢.

推荐答案

您的反对是正确的 - 相反,请使用

Your objection was right- instead, use

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view

来自 UIView,喜欢

from UIView, like

[button.superview convertPoint:button.frame.origin toView:nil];

未经测试,但我认为应该可行.另请参阅 iPhone - 在整个 UIWindow 中获取 UIView 的位置

Not tested, but I believe that should work. Also see iPhone - Get Position of UIView within entire UIWindow

这篇关于在 UIScrollView 绝对屏幕位置内获取 UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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