Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CALayer animates with frame change?

Tags:

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]; 

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?

like image 327
mark Avatar asked Aug 24 '12 04:08

mark


People also ask

Do you have to animate frame-by-frame?

Although it's no longer necessary, it's still used by many animators for the following two purposes: Tradition: To replicate the traditional qualities of hand-drawn animation. Practicality: Certain types of animation (such as stop motion or rotoscope) can only be produced frame-by-frame.

How to add a new layer in animate?

Click the new layer button at the bottom of the timeline. Select Insert > Timeline > Layer. Right-click (Windows) or control+click (Macintosh) a layer name in the timeline and select Insert Layer from the context menu.

What is an animated frame?

Frame-by-frame animation is where each incremental frame (or image) of an animation is drawn individually to create the illusion of movement. This is in contrast to computer generated or motion graphics animation, where the computer can create images on its own within parameters set by the animator.

What is layers in animate cc?

Layers enable you to organize the artwork in your document. You can draw and edit objects on one layer without affecting objects on another layer.


2 Answers

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

like image 165
Scott Avatar answered Oct 07 '22 00:10

Scott


In Swift 4:

CATransaction.begin() CATransaction.setDisableActions(true) /* Your layer / frame changes here */ CATransaction.commit() 
like image 23
JoGoFo Avatar answered Oct 07 '22 00:10

JoGoFo