Stop the animation while it is in progress?

  • Hi I have a simple image that I animate (move horizontally) on the screen from startLoc to endLoc. The animation happens when the user clicks on the Animate button (which triggers the animate action). The animation happens during 6 seconds (I set duration=6.0). There is also a Kill button (which triggers the kill action). What I want is to kill the animation while in progress. I tried to do it by setting location of the image outside screen, but it did not work. How What should I do in order stop the animation while it is in progress?

    - (IBAction)animate:(id)sender
    {
        position.origin.x = startLoc;
        [view setFrame:position];
        position.origin.x = endLoc;
        [NSAnimationContext beginGrouping];
        [[NSAnimationContext currentContext] setDuration:duration];
        [[view animator] setFrame:position];
        [NSAnimationContext endGrouping];
    }

    - (IBAction)kill:(id)sender
    {
        position.origin.x = startLoc;
        [[view animator] setFrame:position];
    }
    @end

          ____________________________________________________________________________________
    Never miss a thing.  Make Yahoo your home page.
    http://www.yahoo.com/r/hs
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today