iPhone: UIImageView Fades in - Howto?

21,701

Solution 1

Initially set the alpha of your imageview as 0 as imageView.alpha = 0;

- (void)fadeInImage 
{
[UIView beginAnimations:@"fade in" context:nil];
    [UIView setAnimationDuration:1.0];
    imageView.alpha = 1.0;
    [UIView commitAnimations];

}

Solution 2

Change the animation duration to what ever length you want.

UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];
myImageView.center = CGPointMake(100, 100);
myImageView.alpha = 0.0;
[self.view addSubview:myImageView];
[UIView animateWithDuration:5.0 animations:^{
     myImageView.alpha = 1.0;
}];

Solution 3

Use below in your UIViewController

// add the image view
[self.view addSubview:myImageView];
// set up a transition animation
CATransition *animate = [CATransition animation];
[animate setDuration:self.animationDelay];
[animate setType:kCATransitionPush];
[animate setSubtype:kCATransitionFade];
[animate setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[self layer] addAnimation:animate forKey:@"fade in"];

Solution 4

this simple code:

[UIView animateWithDuration:5.0 animations:^{
        theImage.alpha = 1.0;
    }];

the UIImage is in the view and is connected via an IBOutlet you can also, set the alpha from the utility panel.

Solution 5

I would use UIView's +transitionWithView:duration:options:animations:completion: It is very efficient and powerful.

[UIView transitionWithView:imgView duration:1 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    imgView.image = [UIImage imageNamed:@"MyImage"];
} completion:nil];
Share:
21,701

Related videos on Youtube

Ian Vink
Author by

Ian Vink

https://mvp.microsoft.com/en-us/PublicProfile/5002789?fullName=Ian%20Vink

Updated on November 03, 2020

Comments

  • Ian Vink
    Ian Vink about 3 years

    I have an UIImageView that I want to fade in.

    Is there a way to enable that on an underlying UIViewController?

    I have translated the simplest answer, though they all work, C# .NET for the MonoTouch users:

    public override void ViewDidAppear (bool animated)
    {
        base.ViewDidAppear (animated);
        UIView.BeginAnimations ("fade in");
        UIView.SetAnimationDuration (1);
        imageView.Alpha = 1;
        UIView.CommitAnimations ();
    }
    
  • clankill3r
    clankill3r over 10 years
    IS it possible to only animate the UIImageView and not the UIView? (and if so how?)
  • ghiboz
    ghiboz over 9 years
    worked for me: I've added a UIImageView from the UI editor and after (i needed to fade out the imageview) simply added the last 3 rows of the example (with alpha = 0.0) and is ok!