Really odd timer behavious, results in flickering?!?!

Discussion in 'iOS Programming' started by gwelmarten, Oct 20, 2012.

  1. gwelmarten macrumors 6502

    Jan 17, 2011
    I've got a UIImageView that is meant to cycle through 5 images. I do this by calling a method every 0.2 seconds to update it with the new UIImage.

    However, I get the flickering effect as shown in the video below. I'm not sure why this is happening, I did think it could be to do with the amount of work and memory required for floats, but since there is only 1 that is meing manipulated I don't think this is the problem.

    Hmm, this won't let me embed the video. See it here:

    I basically call the method below and that is enough to keep the images cycling.
    -(void)startCharacterCycle {
        NSLog(@"Called start character cycle.");
        [self performSelector:@selector(actuallyChangeYouCharacter:) withObject:state1ImageYou afterDelay:1*[nsNumberYouCharacterAnimationSpeed floatValue]];
        [self performSelector:@selector(actuallyChangeYouCharacter:) withObject:state2ImageYou afterDelay:2*[nsNumberYouCharacterAnimationSpeed floatValue]];
        [self performSelector:@selector(actuallyChangeYouCharacter:) withObject:state3ImageYou afterDelay:3*[nsNumberYouCharacterAnimationSpeed floatValue]];
        [self performSelector:@selector(actuallyChangeYouCharacter:) withObject:state4ImageYou afterDelay:4*[nsNumberYouCharacterAnimationSpeed floatValue]];
        [self performSelector:@selector(actuallyChangeYouCharacter:) withObject:state5ImageYou afterDelay:5*[nsNumberYouCharacterAnimationSpeed floatValue]];
        [self performSelector:@selector(startCharacterCycle) withObject:nil afterDelay:6*[nsNumberYouCharacterAnimationSpeed floatValue]];
    Any ideas as to the cause?
  2. Ides macrumors member

    Mar 27, 2012
    You don't need to make your own methods for switching through images, UIImageView already has those.

    myImageView.animationImages = arrayOfImages; // Your images in an NSArray
    myImageView.animationDuration = someTime; // The time it takes to go through images
    myImageView.animationRepeatCount = someRepeatCount; // The number of times to repeat the animation
    [myImageView startAnimating]; // Start the animations
    That's all there is to it!
  3. gwelmarten thread starter macrumors 6502

    Jan 17, 2011
    Well, way to miss something that was staring me in the face all along! Rather than going through all that complex rubbish, this works just as well (UIImageView's animation funciton):

    NSArray *images = [NSArray arrayWithObjects:
                               [UIImage imageNamed:@"image-01.png"],
                               [UIImage imageNamed:@"image-02.png"],
                               [UIImage imageNamed:@"image-03.png"],
                               [UIImage imageNamed:@"image-04.png"],
                               [UIImage imageNamed:@"image-05.png"], nil];
            imageView.animationImages = images;
            imageView.animationRepeatCount = 0;
            imageView.animationDuration = 0.7;
            [imageView startAnimating];
    Thanks PhillipusB!


    Thanks as well - I just figured it out!

Share This Page