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

gwelmarten

macrumors 6502
Original poster
Jan 17, 2011
477
0
England!
Hi
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: http://youtu.be/sLLfQLaXVwQ?hd=1

I basically call the method below and that is enough to keep the images cycling.
Code:
-(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?
Thanks,
Sam
 

Ides

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

Code:
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!
 

gwelmarten

macrumors 6502
Original poster
Jan 17, 2011
477
0
England!
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):

Code:
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!

----------

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

Code:
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!
Thanks as well - I just figured it out!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.