我有动画方法:
-(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]);
}
}
此动画应该使图层不可见,但不会发生:/我做错了什么?
答案 0 :(得分:0)
也许beginTime不正确。您不确定能否删除beginTime的配置并尝试一下。