CALayer动画帧变化? [英] CALayer animates with frame change?

查看:102
本文介绍了CALayer动画帧变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CALayer我添加到我的视图中:

I have a CALayer I've added to my view:

myView.myCALayer = [[CALayer alloc] init];
CGSize size = myView.frame.size;
myView.myCALayer.frame = CGRectMake(0, 0, size.width, size.height);
myView.myCALayer.backgroundColor = [[UIColor blackColor] CGColor];
[myView.layer addSublayer:myView.myCALayer];

当我在更改myView的框架后尝试更改CALayer的框架时,调整大小CALayer动画。我没有给CALayer添加任何动画,所以我不明白这一点。我甚至试图在调整大小之前调用图层上的removeAllAnimations,它仍然可以调整大小。

When I attempt to change the frame of the CALayer after changing the frame of myView, the resize of the CALayer animates. I have added no animation to the CALayer, so I don't understand this. I've even attempted to call removeAllAnimations on the layer before the resize and it still animates the resize.

任何人都知道这里会发生什么?

Anyone know what could be going on here?

推荐答案

实际上有一个隐式动画可以为CALayer设置一些值。您必须在设置新框架之前禁用动画。

There is actually an implicit animation on setting some values for a CALayer. You have to disable the animations before you set a new frame.

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

[myView.myCALayer.frame = (CGRect){ { 10, 10 }, { 100, 100 } ];

[CATransaction commit];

https://developer.apple.com/library/content/documentation/Cocoa /Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html#//apple_ref/doc/uid/TP40004514-CH8-SW3

这篇关于CALayer动画帧变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆