!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> » More Fun With Coordinate Systems -- Mobile Perspectives

More Fun With Coordinate Systems



By deans ~ April 4th, 2009. Filed under: Resources.

Thus far, in my very brief iPhone SDK programming career, I probably have had more bugs caused by each view having its own coordinate space than any other single issue.  Just when I thought that I had it all figured out, I ran into this issue.

If you ask a UIView for its “bounds,” you get back a rectangle, with an origin at (0,0) and a size set to the frame size of the view.  That’s exactly what I would expect.  Now, I know that relative position in a header file means absolutely nothing.  However, the very next property specified in the UIViewGeometry category defined for UIView is “center.”  Guess which coordinate space “center” is in.  Unfortunately, I guessed that it would be in the space of the receiver – WRONG.  It’s actually in the space of the superview.  I even checked the UIView Class Reference documentation.  Surely enough, “The center is specified within the coordinate system of its superview.

I’ve been warned, from now on, I’m always going to refer back to Apple’s Developer Documentation.

Happy coding…

Technorati Tags:  , , ,

Comments are closed.