Iphone 动画到值和从值

Iphone 动画到值和从值,iphone,Iphone,我试图在屏幕上设置标签的动画,但我似乎无法使其正常工作。当前,它会将视图动画化为其他视图 此外,我无法在需要时“停止”动画。我在音乐播放器中使用它在UIView中滚动曲目名称,当我点击Next或Prev时,它必须在动画中间停止并重新开始 - (void)startAnimation { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:10]; [UIView setAni

我试图在屏幕上设置标签的动画,但我似乎无法使其正常工作。当前,它会将视图动画化为其他视图

此外,我无法在需要时“停止”动画。我在音乐播放器中使用它在UIView中滚动曲目名称,当我点击Next或Prev时,它必须在动画中间停止并重新开始

- (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];
}

我假设您要做的是设置标签的动画,使其向左移动50个像素。如果是,您需要更改行:

frame.origin.x = -50

问题是,您正在将帧的新原点设置为-50,即距离视图左侧50像素。相反,你只需要从它的当前位置减去50个像素,这样它就可以相对于原来的位置移动50个像素

frame.origin.x -= 50;