开发者

UIKit: CGAffineTransforms and Composited Animations

开发者 https://www.devze.com 2023-03-19 06:55 出处:网络
I\'ve noticed that when animating things in UIKit, certain types of animations can be composited using standard block-based animations while others cannot. For instance, view开发者_StackOverflow社区.t

I've noticed that when animating things in UIKit, certain types of animations can be composited using standard block-based animations while others cannot. For instance, view开发者_StackOverflow社区.transform interferes with view.frame, but not with view.center. Are these things documented anywhere?

On a related note, because of these compositing issues, I've often resorted to animating mainly using CGAffineTransforms, since they can be composited very easily. Is this a good idea? It seems that applying a transform is different under the hood than simply changing the frame, so I'm not sure if I should be using them to permanently move a view or change its size. Do CGAffineTransforms and view.frame-related changes overlap at all?

Thanks!


For what it's worth, here's Apple's stance on this:

You typically modify the transform property of a view when you want to implement animations. For example, you could use this property to create an animation of your view rotating around its center point. You would not use this property to make permanent changes to your view, such as modifying its position or size a view within its superview’s coordinate space. For that type of change, you should modify the frame rectangle of your view instead.

Source: View Programming Guide for iOS, View and Window Architecture

(I suppose one exception would be permanently rotated views, which would be impossible to accomplish with frame modifications.)

I've also determined that CGAffineTransforms appear to modify the underlying rendered image of a view, not its content, so (for example) applying a CGAffineTransformScale is fundamentally different from expanding the frame. I'm not sure if this is necessarily true, or if it depends on contentMode/other factors.

I'm still not entirely clear on how the frame, bounds, and transform of a view interact. You can, for example, set the frame of a view after applying a rotation, and it'll be relative to the rotated view, whereas modifying the bounds will apply the transformation to the view pre-rotation (IIRC).

0

精彩评论

暂无评论...
验证码 换一张
取 消