CABasicAnimation导致冻结

时间:2014-02-18 11:05:35

标签: ios iphone objective-c

我有这段代码:

- (void) animationErreur {
CABasicAnimation* fade = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
fade.fromValue = (id)[UIColor colorWithRed:1.0f green:0.0f blue:0.0f alpha:0.0f];
fade.fromValue = (id)[UIColor redColor].CGColor;
fade.toValue = (id)[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f];
[fade setDuration:1];
[self.topBar.layer addAnimation:fade forKey:@"fadeAnimation"];
}

每当我调用它时,它都有效,但如果我在动画期间点击视图,它就会崩溃。我已将quartcore框架添加到我的课程中。单击按钮时会调用此代码。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

fade.toValue = (id)[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f].CGColor;

您最后要为toValue行添加.CGColor

- (void) animationErreur {
    CABasicAnimation* fade = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
    fade.fromValue = (id)[UIColor redColor].CGColor;
    fade.toValue = (id)[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f].CGColor;
    [fade setDuration:1];
    [self.topBar.layer addAnimation:fade forKey:@"fadeAnimation"];
}

答案 1 :(得分:-1)

尝试将动画对象设为全局。 EXE_Bad_ACCESS通常是由于弧中对象的不可达性。