【问题标题】:iOS 5: Why doen't shadowopacity repeat animation work? [closed]iOS 5:为什么 shadowopacity 重复动画不起作用? [关闭]
【发布时间】:2012-09-18 02:46:58
【问题描述】:

我需要在我的一个图像视图周围产生发光效果。为此,我决定使用 shadowopacity 属性。

这是我的代码:

imageViewForAnimation.layer.position = viewOrigin;
imageViewForAnimation.layer.shadowColor = [[UIColor yellowColor] CGColor];
imageViewForAnimation.layer.shadowOffset = CGSizeMake(0.0, 0.0);
imageViewForAnimation.layer.shadowRadius = 15.0;
imageViewForAnimation.layer.shadowOpacity = 0.3;
imageViewForAnimation.layer.masksToBounds = NO;
// Set up glow effect
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
anim.fromValue = [NSNumber numberWithFloat:0.0f];
anim.toValue = [NSNumber numberWithFloat:1.0f];
anim.duration = 3.0;
anim.repeatCount = HUGE_VALF;
anim.autoReverses = YES;
[imageViewForAnimation.layer addAnimation:anim forKey:@"shadowOpacity"];

imageViewForAnimation.layer.shadowPath = [UIBezierPath bezierPathWithRect:imageViewForAnimation.bounds].CGPath;

imageViewForAnimation.layer.shadowOpacity = 1.0f;   

但是,动画在运行一次后就停止了。没有重复。 有谁知道为什么?

【问题讨论】:

    标签: ios ios5 calayer shadow cabasicanimation


    【解决方案1】:

    我刚刚在 iOS 5 模拟器上运行了您的代码,它可以工作。唯一的问题是

    中的大写“R”
     anim.autoReverses= YES; 
    

    正确代码:

     anim.autoreverses= YES;
    

    如果您的代码拼写正确,那么问题可能出在您添加动画的位置。正如我所说,我只是在 iOS 5 模拟器上运行了代码,并且工作起来很迷人。 希望这有帮助

    【讨论】:

    • 我在这里添加了这一行,但不是在我的代码中,这就是问题:-)...无论如何你是对的。赞成并标记为正确。谢谢!
    猜你喜欢
    • 2013-06-11
    • 2020-10-21
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-15
    相关资源
    最近更新 更多