首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >隐式属性动画不适用于CAReplicatorLayer吗?

隐式属性动画不适用于CAReplicatorLayer吗?
EN

Stack Overflow用户
提问于 2011-06-29 02:42:54
回答 2查看 1.5K关注 0票数 2

示例代码是here

将显式属性动画替换为隐式属性动画后,动画将中断。

显式动画:

代码语言:javascript
复制
-(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"];

    ...
}

隐式动画:

代码语言:javascript
复制
-(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;       
    ...
}

为什么?

EN

回答 2

Stack Overflow用户

发布于 2012-02-09 23:32:10

当你使用隐式动画时,你不需要使用CATrasaction。请注意,uikit禁用了UIView根层layer的隐式动画

票数 1
EN

Stack Overflow用户

发布于 2011-07-07 20:35:58

您应该将CALayer的代理设置为不同的值,以便在适当的时间查看控制器视图( nitWithNibName:bundle:,awakeFromNib,viewDidLoad和viewWillAppear:animated),请查看此处:Does iPhone OS support implicit animation?

在我的机器上,一次触摸调用animate就能很好地工作。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6511504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档