views:

508

answers:

2

Hello,

I have to calculate an angle beetween two UIImageView and i don't find how to get the UIImageViews coordinates(the four corners coordinates). Is there a property for that?

thanks

A: 

self.frame will give you a CGRect with the coordinates of the view.

Marco Mustapic
Note that if the view is rotated (using the transform property) then the frame property is meaningless. From the UIView documentation:Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.
Mark Bessey
Thank you both. I used the transform property. So i can't use that way (self.frame?!). Precisely i just want to get the angle between the 2 UIImageView. Can you tell me a way to get that angle, please? (i can't try now, my MAC is at work :§)
Albatrox
+2  A: 

You should be able to find any angle with trigonometric functions.

For example, this will find the angle between the centers of two UIImageViews that share a superview:

angle = tan((imageView1.center.y-imageView2.center.y),
            (imageView1.center.x-imageView2.center.x));

It is important that they are in the same superview, otherwise the coordinates will be different. To find angles you need to have an understanding of basic trigonometry.

Tozar