2014-02-18 35 views
-2

))我想動畫UIButton(兩個並行動畫:改變圖像和移動),如下所示,動畫按鈕應該移動後,但在完成動畫按鈕後轉向開始位置。請幫助解決它!提前致謝!iOS:爲什麼對象在動畫合成之後轉到開始位置

- (IBAction)bugOneTapped:(id)sender 
{ 
    [UIView animateWithDuration:1.0 
       animations:^{ 
        self.bugOneButton.imageView.animationImages = 
        [NSArray arrayWithObjects:[UIImage imageNamed:@"bugOne3"],[UIImage imageNamed:@"bugOne2"],[UIImage imageNamed:@"bugOne1"],[UIImage imageNamed:@"bugOne2"],[UIImage imageNamed:@"bugOne3"],[UIImage imageNamed:@"bugOne4"],[UIImage imageNamed:@"bugOne5"],[UIImage imageNamed:@"bugOne4"],nil]; 
        self.bugOneButton.imageView.animationDuration = 0.3; 
        [self.bugOneButton.imageView startAnimating]; 


        self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOneButton.center.y - 50); 
        self.bugOnePositionY = self.bugOnePositionY - 50; 


       }completion:^(BOOL finished) { 
        [self.bugOneButton.imageView stopAnimating]; 
       }]; 

self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOnePositionY); 
} 
+2

你又再次設置中心到完成塊.. – GenieWanted

+0

刪除此self.bugOnePositionY後的初始位置= self.bugOnePositionY - 50; – codercat

+0

謝謝,但我已經改變了上面的Y位置,爲什麼沒有改變? – Romchas

回答

0

在你的代碼刪除以下行

self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOnePositionY); 

它將修正..

+0

不))它不工作! – Romchas

0

@Genie誠徵說的很對,刪除代碼

self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOnePositionY) 

這將重置按鈕位置!

+0

不))它不工作! – Romchas

+0

我認爲你使用的是第三方庫,那麼動畫的時間比你的動畫的時間長,所以當它完成時,會重置它。或者方法stopAnimating導致 – fredZhu

0

re移動此兩個線路

- (IBAction)bugOneTapped:(id)sender 
{ 
    [UIView animateWithDuration:1.0 
       animations:^{ 
        self.bugOneButton.imageView.animationImages = 
        [NSArray arrayWithObjects:[UIImage imageNamed:@"bugOne3"],[UIImage imageNamed:@"bugOne2"],[UIImage imageNamed:@"bugOne1"],[UIImage imageNamed:@"bugOne2"],[UIImage imageNamed:@"bugOne3"],[UIImage imageNamed:@"bugOne4"],[UIImage imageNamed:@"bugOne5"],[UIImage imageNamed:@"bugOne4"],nil]; 
        self.bugOneButton.imageView.animationDuration = 0.3; 
        [self.bugOneButton.imageView startAnimating]; 

        self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOneButton.center.y - 50); 

       }completion:^(BOOL finished) { 
        [self.bugOneButton.imageView stopAnimating]; 
       }]; 


} 
+0

也許,當你使用AnimationBlocks時startAnimating和stopAnimating不是必要的 – GenieWanted

+0

我認爲他使用任何第三方庫製作動畫@GenieWanted – codercat

+0

謝謝,但它也不起作用((( – Romchas

相關問題