开发者

Implicit property animations do not work with CAReplicatorLayer?

开发者 https://www.devze.com 2023-03-15 20:26 出处:网络
The sample code is here. After replacing explicit property animations with implicit property animations, the animation is broken.

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.dur开发者_开发知识库ation = 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?


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


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.

0

精彩评论

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

关注公众号