dan
dan

Reputation: 393

iPhone SDK - Relative position inside another control?

How can I tell the relative position (x & y) of uiimageview B relative (or the "inside of" position ??) of UIImageView B?

example

Upvotes: 1

Views: 207

Answers (2)

wattson12
wattson12

Reputation: 11174

frame is the property you are looking for, it gives you the origin and size of a view, relative to its superview

UIView *a = //outer view
UIView *b = //inner view
[a addSubview:b];

CGRect bFrame = b.frame; 
NSLog(@"%@", NSStrinFromCGRect(bFrame)); //will be something like (100, 100, 40, 20)

edit: I didnt realise they werent subviews (I dont use IB), so you will need to convert to the coord system of a:

   CGRect bFrame = [a convertRect:b.frame fromView:b.superView];

Upvotes: 1

tkanzakic
tkanzakic

Reputation: 5499

to know the position of a view respect another one use [aView convertPoint:toView:] or [aView convertRect:toView:], you can find the documentation of this functions here and here.

Upvotes: 2

Related Questions