On Jun 18, 2009, at 8:19 PM, David Duncan wrote:

On Jun 18, 2009, at 11:01 AM, WT wrote:

Ultimately, I have some rectangular area on the 2D screen of an iPhone or a Mac, and it has a center point (which, I understand, doesn't *have* to be halfway through the bounds), whose coordinates are measured in the coordinate system of the rectangle's superview. I then apply a translation to this rectangle and it ends up somewhere else on that screen. Assuming that the rectangle's superview was not translated along as well, I cannot see how the coordinates of the rectangle's center would not have changed.


Your confusing the geometric center of the view's rectangle with the center property of the view. Specifically in code if you do this:

CGPoint c = view.center;
view.transform = CGAffineTransformMakeTranslation(20, 20);
CGPoint visualCenter = CGPointMake(CGRectGetMidX(view.frame), CGRectGetMidY(view.frame));
CGPoint c2 = view.center;

Then you will find that c == c2, c != visualCenter, and c2 != visualCenter.

This is why using translations for transforms is very confusing. You expect the center of the view to change, but it does not. This is by design.

Ok, simple enough. But, then, IMHO, "center" is a terrible name for the view.center property.

Wagner
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to