2010-04-28 65 views
1

嘿,所有的,在這裏有一個小問題,並不能弄清楚我做錯了什麼。我正在嘗試向上和向下反覆動畫UIView。當我開始播放時,它會正確地下降然後備份,但會立即開始播放到動畫的「最終」位置。代碼如下:iPhone - UIView動畫沒有正確循環

UIImageView *guide = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]]; 
    guide.frame = CGRectMake(250, 80, 30, 30); 

    [self.view addSubview:guide]; 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationDuration:2]; 
    [UIView setAnimationRepeatAutoreverses:YES]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 

    guide.frame = CGRectMake(250, 300, 30, 30); 

    [UIView setAnimationRepeatCount:10]; 
    [UIView commitAnimations]; 

在此先感謝!

回答

0

你可以設置setAnimationDidStopSelector自定義函數和自定義功能,您可以設置多個動畫(甚至遞歸)。看到我對另一個問題的回答here

通常我會定義一個動畫結構(AnimationPath in the example)來協調整個動畫(比如說一個計數器)。

3

這是一個老問題,但如果有人正在看這個,你可以使用分數重複計數來結束所需的狀態。如果您從A動畫到B並使用自動反轉,則每個重複將如下所示:A - > B - > A.由於您想在最後一個動畫上以B結尾,而不是A,只需做到最後一次只重複中途(到B):

[UIView setAnimationRepeatCount:10.5]; 

就是這樣!