1

以下代码指向内存分配泄漏(使用分析器中的分配工具) - 有人可以指出原因 - 我正在使用 aCABAsicAnimation来旋转 aUIImageView

-(void)SetGaugeToValueInAngles: (int)newValue
{

    static int oldValue = 0;

    int delta = newValue - oldValue;

    CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    [rotate setDelegate:self];
    rotate.fromValue = [NSNumber numberWithFloat:oldValue/57.2958];
    rotate.removedOnCompletion = NO;
    rotate.fillMode = kCAFillModeForwards;

    rotate.toValue = [NSNumber numberWithFloat:  newValue/57.2958];

    rotate.duration = 10.0; // seconds

    [self.UIImageViewPressureMark.layer addAnimation:rotate forKey:nil]; // "key" is optional

    NSLog(@"Old Value %d New Value %d", oldValue, newValue);

    oldValue = newValue;
}
4

2 回答 2

3

如果您设置removeOnCompletionNO图层将保留动画,直到您将其移除。

您应该设置removedOnCompletionYES,或者检查图层是否已经有动画并在添加下一个 newValue 时将其删除

于 2013-06-17T14:15:05.547 回答
0

当你释放这个类的实例时,你应该调用 removeAnimationForKey。执行以下操作 1.change

[self.UIImageViewPressureMark.layer addAnimation:rotate forKey:nil];

[self.UIImageViewPressureMark.layer addAnimation:rotate forKey:@"myAnimation"]; 

在您的方法“SetGaugeToValueInAngles”中

2.当你释放这个类的实例时调用下面的方法

- (void)invalateAnimation
{
    [self.UIImageViewPressureMark.layer removeAnimationForKey:@"myAnimation"];
    self.UIImageViewPressureMark.layer = nil;
}
于 2015-08-06T09:10:26.537 回答