Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: UIImageView Fades in - Howto?

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 ();
}
like image 615
Ian Vink Avatar asked Apr 12 '11 08:04

Ian Vink


2 Answers

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];

}
like image 106
visakh7 Avatar answered Oct 08 '22 15:10

visakh7


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;
}];
like image 31
Sabobin Avatar answered Oct 08 '22 15:10

Sabobin