Objective c 层不更改动画中的不透明度

Objective c 层不更改动画中的不透明度,objective-c,calayer,cabasicanimation,Objective C,Calayer,Cabasicanimation,我有一个动画的方法: -(void)AnimateRemovedScoreBall:(Field*)ballToRemove { @try { CABasicAnimation *flash = [CABasicAnimation animationWithKeyPath:@"opacity"]; flash.fromValue = [NSNumber numberWithFloat:1.0]; flash.toValue = [N

我有一个动画的方法:

-(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]);
    }
}

此动画应使层不可见,但不会发生:/n我做错了什么?

可能起始时间不正确。你能删除beginTime的配置并试一试吗,我不确定。

关于球的创建或AnimateRemoveScoreBall方法,我没有任何想法。也许问题在于你如何称呼AnimateRemoveScoreBall。您可以发布调用该方法的代码吗?您确定“FindFieldWithPoint:”方法返回有效字段吗?