2012-07-02 173 views
1

我的程序總是崩潰:類方法沒有找到

-(void) moveImage:(UIImageView *)image duration:(NSTimeInterval)duration curve:(int)curve x:(CGFloat)x y:(CGFloat)y key:(NSString *)key 
{ 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:duration]; 
[UIView setAnimationCurve:curve]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDidStopSelector:@selector(animationDidStop:)]; 

CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y); 
image.transform = transform; 
[UIView commitAnimations]; 
} 

調用此方法,並在結束時,我想它來調用波紋管的方法:

-(void)animationDidStop:(NSString *)key 
{ 
if (key == @"burn") { 
    //The burn card has been moved and stopped. Ready for the next. 
    [self annPlayerRight]; 
} 

} 

我到底做錯了什麼?

+0

可能的重複[蘋果拒絕的應用程序,因爲animationDidStop:已完成:上下文:是非公開API](http://stackoverflow.com/questions/3455604/apple-rejected-app-because-of-animationdidstopfinishedcontext-是非公開的) – trojanfoe

回答

4

嗯,是因爲setAnimationDidStopSelector:withObject:方法不存在... 的UIView的實際方法是:爲setAnimationDidStopSelector方法 + (void)setAnimationDidStopSelector:(SEL)selector

(注意,withObject:部分缺失)

+0

那就是我的想法,我將如何發送它的參數? – JH95

+0

@JakeHoskins請參閱Jennis的答案... – Alladinian

3

檢查Documentation

動畫結束後發送給動畫委託的消息。默認值是NULL。選擇器應該是這樣的形式:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context. 

所以,當你調用beginAnimations有參數context這將是訪問在animationDIdStop方法。

希望這會有所幫助。

+0

我看到了,但我仍然困惑,所以它不可能通過發送一個字符串作爲參數:[UIView setAnimationDidStopSelector:@selector(animationDidStop :)]; – JH95

+0

現在沒有。您只能通過上下文發送動畫。 –

+0

只是詢問'[UIView beginAnimations:nil context:NULL]是什麼問題;'在上下文中發送參數? –