2011-06-17 57 views
0

我試圖在屏幕上爲標籤製作動畫,但我似乎無法正常工作。目前它激發了對其他觀點的看法。往返於動畫的動畫

另外我不能在需要時「停止」動畫。我在音樂播放器中使用它在UIView上滾動曲目名稱,當我點擊下一個或上一個時,它必須停止中間動畫並重新開始。

- (void)startAnimation { 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:10]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:)]; 

    CGRect frame = trackName.frame; 
    frame.origin.x = -50; 
    trackName.frame = frame; 

    [UIView commitAnimations]; 
} 

- (void)animationDidStop:(id)sender { 
    NSLog(@"animationDidStop"); 

    CGRect frame = trackName.frame; 
    frame.origin.x = 194; 
    trackName.frame = frame; 

    [self startAnimation]; 
} 

回答

1

我假設你想要做的是動畫標籤,使它向左移動50個像素。如果是這樣,您需要更改行:

frame.origin.x = -50 

frame.origin.x -= 50; 

的問題是,您正在設置幀到-50新的原點,這是50個像素關閉左側的看法。相反,您只需從當前位置減去50個像素,以便相對於原來的位置移動50個像素。