2012-03-28 58 views
0

當我按下一個按鈕時,我想運行一系列方法methodOne然後methodTwo然後methodThree。當我現在運行它時,我只能得到最後一個運行的方法。我希望他們按順序奔跑。我究竟做錯了什麼。運行一系列方法

@implementation JackAnimationViewController 
@synthesize color; 



- (IBAction)button:(id)sender { 
    [self methodOne]; 
    [self methodTwo]; 
    [self methodThree]; 
} 

-(void) methodOne{ 
    color.animationImages = [NSArray arrayWithObjects: 
      [UIImage imageNamed:@"greenDim.png"], 
      [UIImage imageNamed:@"GreenPressed.png"], 
      [UIImage imageNamed:@"greenDim.png"], 
      [UIImage imageNamed:@"GreenPressed.png"],nil];  
    [color setAnimationRepeatCount:2]; 
    color.animationDuration = 1; 
    [color startAnimating];} 

-(void) methodTwo{ 
    color.animationImages = [NSArray arrayWithObjects: 
      [UIImage imageNamed:@"yellowDim.png"], 
      [UIImage imageNamed:@"YellowPressed.png"], 
      [UIImage imageNamed:@"yellowDim.png"], 
      [UIImage imageNamed:@"YellowPressed.png"],nil];  
    [color setAnimationRepeatCount:2]; 
    color.animationDuration = 1; 
    [color startAnimating];} 

-(void) methodThree{ 
    color.animationImages = [NSArray arrayWithObjects: 
      [UIImage imageNamed:@"yellowDim.png"], 
      [UIImage imageNamed:@"GreenPressed.png"], 
      [UIImage imageNamed:@"yellowDim.png"], 
      [UIImage imageNamed:@"GreenPressed.png"],nil];  
    [color setAnimationRepeatCount:2]; 
    color.animationDuration = 1; 
    [color startAnimating];} 


@end 
+0

什麼類的類是'color'?你能發佈.h文件嗎? – rosslebeau 2012-03-28 00:05:48

+0

基於方法名稱的@passedpawn'color'看起來像一個'UIImageView'。 – Jonah 2012-03-28 01:05:07

回答

0

您反覆設置animationImages在每個這些方法同樣UIImageView。每次你這樣做,它將取代以前的設置並取消該動畫。

startAnimating不同步,你會在何時結束methodOne定義動畫methodOne,而不是後立即執行methodTwo

爲了獲得效果,我相信你正在尋找你可以建立一個單一的更大的數組,包含所有三個動畫中的圖像,你想循環它們的順序。 或者,您可以安排methodTwomethodThree在先前動畫完成後調用,但是如果不再需要或者您想取消動畫,則需要準備取消這些調用。

+0

你怎麼安排方法 – 2012-03-28 01:29:43

+0

看看了'NSTimer'類還有'-performSelector:withObject:afterDelay:'和'+ cancelPreviousPerformRequestsWithTarget:選擇:對象:對''NSObject'方法。 – Jonah 2012-03-28 02:03:55