Re: Group CGAffineTransform Animations?
Re: Group CGAffineTransform Animations?
- Subject: Re: Group CGAffineTransform Animations?
- From: David Duncan <email@hidden>
- Date: Wed, 17 Jun 2009 15:42:03 -0700
On Jun 17, 2009, at 2:11 PM, WT wrote:
You're absolutely correct in general, but - if I'm not mistaken -
CGAffineTransform rotations and scalings already do their thing with
respect to the center of the view they're being applied to. In fact,
I tested that before writing my solution to the OP's problem. And
that is indeed the source of the problem. Rotations and scalings, as
implemented by CGAffineTransform, are with respect to the view's
center but translations are with respect to the view's origin.
Therefore, if you scale while you translate, the view's origin
changes and the translation is no longer being applied with the
correct offset.
To be honest, I'm a bit surprised that CGAffineTransform rotations
and scalings are already defined with respect to the center of the
view. There's still a part of my brain that thinks that that isn't
true, but my tests indicated otherwise.
All transforms are with respect to the view's center. The view's frame
is an artifact of the view's center, and the frame is calculated based
on a number of parameters of the view, part of which is why the
documentation says not to rely on the frame of a view if you've set a
transform on the view.
The issue with a translation is that it starts to confuse your
expectations of the relationship between a view's center and the
view's frame, because the center isn't altered by the transform, only
the frame is. This is also why I recommend not using translations as
part of your transform if they are not necessary, because then you
look at the center of the view and you discover that it hasn't
actually moved, yet your view is clearly not where it was before you
set the transform.
Of note at this point is that the view's center is in its super view's
coordinate system, while the view's bounds is in its own coordinate
system (and thus the origin is usually, but need not be, CGPointZero).
Your solution works because you've scaled the coordinate system, so
the translation needs to be scaled too (to get the change specified by
the translation). Effectively, you've changed the coordinate system
for defining the frame without changing the coordinate system of the
view's center (because that coordinate system is defined by the super
view).
At the Core Animation level (where this all really lives) the frame of
a layer is calculated based on the layer's position, bounds.size,
anchorPoint and transform. The position determines its location in the
superlayer, the bounds.size determines the extent of the layer, the
anchorPoint determines how the extent is positioned relative to the
position, and the transform is applied to that final rectangle to
determine the actual position on screen. The frame rectangle is then
extracted from that in a process that while meaningful tends to be
useless to developers.
--
David Duncan
Apple DTS Animation and Printing
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden