Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone fading of images

wat i want is to show an image in image view and fade the image after 5 seconds and show the next image .the images are stored in an array objects...i was able to make a successful transition between images after 5 seconds.what i want is to fadeout the first image after 5 seconds and show the next one this got to happen in an infinite loop...below is the code and it works really good for normal transition between images..wat i want is fading of images...and were to add fading transition in the below code

- (void)viewDidLoad {

    imgView.animationImages=[NSArray arrayWithObjects:  
                             [UIImage imageNamed:@"lori.png"],
                             [UIImage imageNamed:@"miranda.png"],
                             [UIImage imageNamed:@"taylor.png"],
                             [UIImage imageNamed:@"ingrid.png"],
                             [UIImage imageNamed:@"kasey.png"], 
                             [UIImage imageNamed:@"wreckers.png"], nil];


    imgView.animationDuration=20.0;
    imgView.animationRepeatCount=0;
    [imgView startAnimating];
    [self.view addSubview:imgView];
    [imgView release];



    [super viewDidLoad];
}
like image 736
kingston Avatar asked Apr 11 '11 08:04

kingston


People also ask

Why are my photos fading?

Sunlight is the most common cause of fading, but the mix of chemicals in the air will also expediate the aging process of photographs. The constant medley of dust, aerosols, cleaners, and smoke—whether from cigarettes, fireplaces, or cooking—can cause unprotected photographs to fade and deteriorate.

Why do my photos look dull on iPhone?

Exposure refers to the brightness of an image. If you don't get the exposure right, your photo will either be too bright (over-exposed) or too dark (under-exposed). If the photo is under-exposed, it will lack detail in the shadows (dark areas). And the highlights (bright areas) may appear dull.


1 Answers

You can use a repeating NSTimer to call a special method which animates the image views alpha property from 0.0 to 1.0 continuously. Here is some code I have written which works:

- (void)viewDidLoad {
    imgView.animationImages=[NSArray arrayWithObjects:  
                             [UIImage imageNamed:@"lori.png"],
                             [UIImage imageNamed:@"miranda.png"],
                             [UIImage imageNamed:@"taylor.png"],
                             [UIImage imageNamed:@"ingrid.png"],
                             [UIImage imageNamed:@"kasey.png"], 
                             [UIImage imageNamed:@"wreckers.png"], nil];



    imgView.animationDuration=20.0;
    imgView.animationRepeatCount=0;
    [imgView startAnimating];
    [self.view addSubview:imgView];
    [imgView release];
    //The timers time interval is the imageViews animation duration devided by the number of images in the animationImages array. 20/5 = 4 
    NSTimer *timer = [NSTimer timerWithTimeInterval:4.0 
                                              target:self 
                                            selector:@selector(onTimer) 
                                            userInfo:nil 
                                             repeats:YES];

    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    [timer fire];

    [super viewDidLoad];
}

//It is important that the animation durations within these animation blocks add up to 4 
//(the time interval of the timer). If you change the time interval then the time intervals 
//in these blocks must also be changed to refelect the amount of time an image is displayed. 
//Failing to do this will mean your fading animation will go out of phase with the switching of images.   

-(void)onTimer{
        [UIView animateWithDuration:3.0 animations:^{
            imgView.alpha = 0.0; 
        }];
        [UIView animateWithDuration:1.0 animations:^{
            imgView.alpha = 1.0; 
        }];
    }

If you want the fade duration to last for 5 seconds instead of 4, you need to increase your image views animationDuration property to 25, and then increase the fade animation durations in the two blocks such that the sum fade time = 5.

like image 89
Sabobin Avatar answered Oct 14 '22 09:10

Sabobin