Search code examples
iphoneimageimageviewfading

iphone image change with motion


hi is there any way to set image [uiimage image named@"abc.png"] with the motion effect means the image should not be changed at once , it need to change with very slow motion effect so that user can see that image is now changing .

Thanks in advance


Solution

  • * Method one to perform the Animation *

    Step 1 : Add following framework in your project and import it to your .m file

    #import <QuartzCore/QuartzCore.h>
    

    Step 2 : Write following code in your ImageChange method

    imageView.image = [UIImage imageNamed:@"newImage.jpg"];
    
    CATransition *transition = [CATransition animation];
    transition.duration = 1.0f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    
    [imageView.layer addAnimation:transition forKey:nil];
    

    * Method Two to perform the Animation *

    [UIView transitionWithView:YourImageView
                  duration:0.2f
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
                    YourImageView.image = newImage;
                } completion:NULL];