图层不会改变动画中的不透明度

问题描述 投票:0回答:1

我有动画方法:

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

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

objective-c calayer cabasicanimation
1个回答
0
投票

也许beginTime不正确。你可以删除beginTime的配置,并试一试,我不确定。

© www.soinside.com 2019 - 2024. All rights reserved.