Implicit property animations do not work with CAReplicatorLayer?

一个人想着一个人 提交于 2019-12-12 19:20:42

问题


The sample code is here.

After replacing explicit property animations with implicit property animations, the animation is broken.

Explicit animation:

-(void)animate:(id)sender {
    ...
    //Transform Animation
    animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    animation.fromValue = [NSValue valueWithCATransform3D: CATransform3DIdentity];
    animation.toValue = [NSValue valueWithCATransform3D: t];
    animation.duration = 1.0;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeBoth;
    [subLayer addAnimation:animation forKey:@"transform"];

    //Opacity Animation
    animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    animation.fromValue = [NSNumber numberWithFloat:1.0];
    animation.toValue = [NSNumber numberWithFloat:0.0];
    animation.duration = 1.0;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeBoth;
    [subLayer addAnimation:animation forKey:@"opacity"];
    ...
}

-(void)reset:(id)sender {       
    ...
    //Transform Animation
    animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    animation.fromValue = [NSValue valueWithCATransform3D: t];
    animation.toValue = [NSValue valueWithCATransform3D: CATransform3DIdentity];
    animation.duration = 1.0;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeBoth;
    [subLayer addAnimation:animation forKey:@"transform"];

    //Opacity Animation
    animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    animation.fromValue = [NSNumber numberWithFloat:0.0];
    animation.toValue = [NSNumber numberWithFloat:1.0];
    animation.duration = 1.0;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeBoth;
    [subLayer addAnimation:animation forKey:@"opacity"];

    ...
}

Implicit animation:

-(void)animate:(id)sender {
    ...
    //Transform Animation
    [CATransaction setAnimationDuration:1];
    subLayer.transform = t;

    //Opacity Animation
    [CATransaction setAnimationDuration:1];
    subLayer.opacity = 0;
    ...
}

-(void)reset:(id)sender {       
    ...
    //Transform Animation
    [CATransaction setAnimationDuration:1];
    subLayer.transform = CATransform3DIdentity;

    //Opacity Animation
    [CATransaction setAnimationDuration:1];
    subLayer.opacity = 1;       
    ...
}

Why?


回答1:


u don't need to use CATrasaction when you use implicit animation. be carefull that uikit disables the implicit animation of layer which is a root layer of UIView




回答2:


You should to set CALayer's delegate to something different that view controllers view at an appropriate time (none of nitWithNibName:bundle:, awakeFromNib, viewDidLoad, and viewWillAppear:animated), look here: Does iPhone OS support implicit animation? .

On my machine calling animate on a touch worked very nicely.



来源:https://stackoverflow.com/questions/6511504/implicit-property-animations-do-not-work-with-careplicatorlayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!