[英]iOS 5 exc_bad_access code=2 with CABasicAnimation
我收到這個錯誤:
使用此代碼:
-(void)lowerGUI {
[mainGUI.layer addAnimation:guiLower forKey:@"transform.translation.y"];
}
我有一個UIView,我正在上下動畫,如果需要的話可以將它移開。 我在viewDidLoad中設置了我的動畫:
guiLower = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
guiLower.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
guiLower.duration = 1;
guiLower.fromValue = [NSNumber numberWithFloat:320];
guiLower.toValue = [NSNumber numberWithFloat:481];
代碼構建並運行正常,但是當我單擊按鈕運行動畫時,會出現錯誤。
有任何想法嗎?
謝謝。
您可能應該擁有對動畫的引用:
guiLower = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
在您的班級的ivar或屬性中,並確保您分配給它的對象被正確保留。 實際上, EXC_BAD_ACCESS
通常是通過訪問已經解除分配的對象實例引起的。
例:
在.h文件中:
@property (nonatomic, retain) CABasicAnimation* guiLower;
在.m文件中:
@synthesize guiLower;
...
self.guiLower = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.