views:

40

answers:

1

I have a button on a view, I want to add another button next to it when the first button is touched. Therefore I need it's top left corner to do the math.

Here's what is puzzling me greatly: // this code is executed when the button is pressed

NSLog(@"X:%f",moreButton.frame.origin.x);

that returns on the first and second click the followings:

2010-04-24 22:58:25.883 iPad PopOver[8095:40b] X:-1.999002 2010-04-24 22:58:25.884 iPad PopOver[8095:40b] Y:0.000000

why and how can I get the x,y of an existing button on the view? (button created via IB)

Thanks! mE

ps: I have looked at similar posts and my code looks fine but I keep getting zeros (it's an ipad app if matters in any way)

A: 

Try the following and see if this changes things, your code strictly should work, but I usually use an integer formatter.

NSLog(@"X:%d Y%d", moreButton.frame.origin.x, moreButton.frame.origin.y);

Once you've cracked that, you also have the following methods you can perform on the button that you may find useful

convertPoint:toView:
convertPoint:fromView:
convertRect:toView:
convertRect:fromView:
adam
Coordinates are specified as floats, so the format shouldn't be a problem. Transforms can make frames appear to have unusual values, so it might be worth using he methods you suggest to get the coords for the window (just use nil).
Paul Lynch