Change animation time for properties of a CALayer

前端 未结 3 518
遇见更好的自我
遇见更好的自我 2021-02-04 16:27

I have a CALayer to animate a change in its image contents. Now, how can I change how long it takes for this animation to take place?

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 17:18

    A different way to do this:

    [CATransaction begin];
    [CATransaction setValue:[NSNumber numberWithFloat:2.5f] forKey:kCATransactionAnimationDuration];
    //Perform CALayer actions, such as changing the layer contents, position, whatever.
    aCALayerObject.contents = [self newCALayerContents];    
    [CATransaction commit];
    

    That code would animate the change of the CALayer's contents over 2.5 seconds. You can also use this to disable all animations completely. Like this:

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

提交回复
热议问题