我有动画方法:
-(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]);
}
}
这个动画应该使图层不可见,但它没有发生:/我做错了什么?