2012-08-04 57 views
0

我想製作一個IBAction,當被調用時會使圖像「流暢地移動」一定量的像素。現在我有一個讓圖像向左移動10個像素的方法,但它只是傳送到那裏。我希望圖像移過來,就像它的行走不是神奇地結束在那裏。使圖像更「流暢地」移動

這裏是我有:

- (IBAction)moveImageLeft:(id)sender 
{ 
    y = y + 10; 
    myImageView.frame = CGRectMake(x, y, 45, 56); 
} 
+0

查看動畫。我不使用iOS,但'UIView'的'beginAnimation:'等可能值得一看? – Vervious 2012-08-04 04:26:58

回答

2
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationDelay:1.0]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 

y = y + 10; 
myImageView.frame = CGRectMake(x, y, 45, 56);   
[UIView commitAnimations]; 
+0

Good Work .. + 1我也是。 – 2012-08-09 05:09:25

5

@酒窩的答案是正確的。但是,僅供參考,這是另一種方式。它被稱爲動畫塊,在我看來,使整個動畫過程更容易。

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
    y = y + 10; 
    myImageView.frame = CGRectMake(x, y, 45, 56); 
}completion:^(BOOL finishedAnimating){ 
    if (finishedAnimating == YES) { 
     NSLog(@"animation finished");//you can put your own completion handler events here 
    } 
}]; 
+0

它有什麼幫助? – user1438042 2012-08-04 06:56:09

+1

@ user1438042它一切都一樣,我只是認爲它是一種更簡潔,更有組織的動畫表演方式。 – 2012-08-04 06:57:21

+0

好了1先生你先生 – user1438042 2012-08-04 07:02:42