【问题标题】:Layer not change opacity in animation图层不改变动画中的不透明度
【发布时间】:2013-09-17 19:33:22
【问题描述】:

我有动画方法:

-(void)AnimateRemovedScoreBall:(Field*)ballToRemove
{
    @try
    {
        CABasicAnimation *flash = [CABasicAnimation animationWithKeyPath:@"opacity"];
        flash.fromValue = [NSNumber numberWithFloat:1.0];
        flash.toValue = [NSNumber numberWithFloat:0.0];
        flash.beginTime = CACurrentMediaTime() + 1;
        flash.duration = 1.0;        // 1 second
        flash.fillMode = kCAFillModeForwards;
        flash.removedOnCompletion = NO;
        flash.additive = NO;
        [ballToRemove.ballLayer addAnimation:flash forKey:@"flashAnimation"];
    }
    @catch(NSException* ex)
    {
        NSLog(@"Bug captured in method AnimateRemovedScoreBall: %@ %@",ex, [NSThread callStackSymbols]);
    }
}

球层是这样创建的:

-(CALayer*)CreateBallLayer:(CGColorRef)color coordinates:(CGRect)coordinates
{
    CALayer *ballLayer = [CALayer layer];
    @try
    {
        ballLayer.frame = coordinates;
        ballLayer.backgroundColor = color;
        ballLayer.masksToBounds = YES;
        [ballLayer setCornerRadius:25/2];
    }
    @catch(NSException* ex)
    {
        NSLog(@"Bug captured in method CreateBallLayer: %@ %@",ex, [NSThread callStackSymbols]);
    }
    return ballLayer;
}

动画方法的调用者

-(void)RemoveScoreBalls:(NSArray*)scorePoints
{
    @try
    {
        for (NSValue* pointValue in scorePoints) {
            CGPoint point = [pointValue CGPointValue];
            Field* field = [self FindFieldWithPoint:point];
            [self AnimateRemovedScoreBall:field];
            NSInteger fieldIndex = [self.fieldsArray indexOfObject:field];
            field.ballColor = nil;
            field.ballLayer.backgroundColor = nil;
            field.ballLayer = nil;
            [self.fieldsArray replaceObjectAtIndex:fieldIndex withObject:field];
        }
    }
    @catch(NSException* ex)
    {
        NSLog(@"Bug captured in method RemoveScoreBalls: %@ %@",ex, [NSThread callStackSymbols]);
    }
}

这个动画应该使图层不可见,但它没有发生:/我做错了什么?

【问题讨论】:

  • 关于球的创建或 AnimateRemoveScoreBall 方法没有什么让我大吃一惊的。也许问题在于您如何调用 AnimateRemoveScoreBall。你能发布调用该方法的代码吗?
  • 你确定“FindFieldWithPoint:”方法返回一个有效的字段吗?

标签: objective-c calayer cabasicanimation


【解决方案1】:

也许 beginTime 不正确。能不能去掉beginTime的配置,试试看,我不确定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-25
    • 2023-04-09
    • 2021-09-11
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 2015-09-28
    • 2011-08-27
    相关资源
    最近更新 更多