0

我有动画方法:

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

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

4

1 回答 1

0

也许 beginTime 不正确。你能删除beginTime的配置,试试看,我不确定。

于 2018-09-04T03:32:04.920 回答