2012-05-31 39 views
0

我發現了這樣的錯誤:iOS 5的EXC_BAD_ACCESS代碼= 2 CABasicAnimation

enter image description here

有了這個代碼:

-(void)lowerGUI { 
[mainGUI.layer addAnimation:guiLower forKey:@"transform.translation.y"]; 

}

我有一個UIView其中I」如果需要,上下動畫可以將其移開。我建立了我的動畫在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]; 

的代碼生成和運行正常,但是當我點擊按鈕,運行動畫,出現錯誤。

任何想法?

謝謝。

+0

您使用ARC

在.h文件中

?是'guiLower'屬性? – sergio

+0

否ARC,guiLower是一個CABasicAnimation。 – mrEmpty

回答

2

有機會,你應該持有一個參考動畫:

guiLower = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; 
在你的類的實例變量或財產

,並確保分配給它的對象是正確保留。確實,EXC_BAD_ACCESS通常是由訪問一個已經釋放的對象實例引起的。

例子:

@property (nonatomic, retain) CABasicAnimation* guiLower; 

在.m文件:

@synthesize guiLower; 

... 

self.guiLower = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; 
... 
+0

對它進行排序,謝謝。動畫不會動畫,但這是另一回事。這是瞬間的,它忽略了時間。但嘿嘿:) – mrEmpty

+0

作爲一個更新,最後我做了一個簡單的UIView動畫,對於如此簡單的事情更有意義。 – mrEmpty

相關問題