【问题标题】:How to access the current cordinate of UIButton from the super view, when occur the UIGestureRecognizerStateEnd发生 UIGestureRecognizerStateEnd 时如何从超级视图访问 UIButton 的当前坐标
【发布时间】:2011-12-20 10:45:44
【问题描述】:

我是 iOS 开发的新手。现在我正在实现一个UIPanGestureRecognizer 模型应用程序。我有一个UIButton 用于UIPanGestureRecognizer。我的问题是,如何从超级视图访问UIButton的驻留坐标(如UIView、UIScrollView等?)

如果有人知道,请帮助我。

【问题讨论】:

    标签: objective-c cocoa-touch uiview uibutton uipangesturerecognizer


    【解决方案1】:

    你可以使用

    CGRect rectInSuperView = [button convertRect:button.frame toView:superview];
    

    查看documentation

    【讨论】:

    • 感谢您的重播。我无法获得 UIButton 的确切坐标。在我的情况下,UIButton 坐标是 (109,176,72,37) 但 convertRect:toView: 返回值是 (218,352,72,37),值变化的原因是什么?
    • 我明白了,把代码改成CGRect rectInSuperView = [[button superview] convertRect:button.frame toView:Yourview];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多