如何获取UI按钮iPhone的X和Y位置

问题描述:

有人可以告诉我如何在可可中获取UIButton的x和y位置吗?

Could somebody show me how to get the x and y position of a UIButton in cocoa?

单击时按钮在屏幕上移动并且我想使用它当前位置相对于它定位另一个UIBUtton。

The button moves on the screen when clicked and I want to use it's current position to position another UIBUtton relative to it.

我尝试过使用

CGRect rect=[myButton imageRectForContentRect];

编译器告诉我myButton可能无法响应imageRectForContentRect。

The compiler tells me that myButton may not respond to imageRectForContentRect.

使用

myButton.frame

特别是对于位置,请使用myButton.frame.origin.x和myButton.frame.origin.y。这将是左上角。

Specifically for position, use myButton.frame.origin.x and myButton.frame.origin.y. That would be the top left corner.