Resolved Get current frame of animation?

Discussion in 'iOS Programming' started by xArtx, Jan 16, 2013.

  1. xArtx, Jan 16, 2013
    Last edited: Jan 16, 2013

    xArtx macrumors 6502a

    Mar 30, 2012
    Hi Guys,
    I have this two frame animation running in a UIView:
        NSArray *animationFrames = [NSArray arrayWithObjects:
                                    [UIImage imageNamed:@"Frame1.PNG"],
                                    [UIImage imageNamed:@"Frame2.PNG"],
        myImageView = [[UIImageView alloc] init];
        myImageView.animationImages = animationFrames;
        myImageView.bounds = CGRectMake(0, 0, 50, 50);
        myImageView.animationDuration = 1.0;
        myImageView.animationRepeatCount = 0;
        [myImageView startAnimating];
    It swaps frames every second forever fine.
    Is there a way that I can later tell which frame is currently being shown?
    I don't want, or need to interrupt it.

    Any help appreciated :)
    Cheers, Art.
  2. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    Well I didn't find whatever is indexing the images, but you can set the loop to
    run just once and start a timer when you start animating.
    Then when the timer reaches the animation duration you can restart the timer
    and the animation.

    Then any time you can work out the animation frame by looking at the timer.
  3. ArtOfWarfare macrumors G3


    Nov 26, 2007
    I wonder if the performance differs significantly from having it loop endlessly?
  4. KoolStar macrumors demi-god


    Oct 16, 2006
    It looks like UIImageView behind the scenes uses a timer to flip through the images. You can look at a github class to do some introspection on UIImageView if you want to find out a few more details about how the animation works.

  5. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    It looks like a situation where some plain C would be better,
    although I didn't chime in on that discussion, I have an opinion.

    You could index the individual UIImages in a quartz2D view,
    and save yourself a counter. You could also know there's no overhead
    in starting and stopping because you're just resetting an index var,
    and of course you'd have access to the current index because you declared it.

    Somehow I fell like I'm falling into the clutches of Satan by being too lazy to
    do it, even though I can.

Share This Page