cyclingIsBetter
cyclingIsBetter

Reputation: 17591

IOS: set alpha in a UIImage

I have an UIImage and I want to set its alpha at 0.00 after 3 seconds... In my UIImage there is a picture that I want to immediately see when I go in a view, but after 3 second it must disappear.

Upvotes: 6

Views: 13338

Answers (4)

bdparrish
bdparrish

Reputation: 2764

You can always remove the sub-child view from the parent.

[imageView removeFromSuperview];

you can always add it later with

[self.view addSubview:imageView];

Upvotes: 0

Peter DeWeese
Peter DeWeese

Reputation: 18333

This will make it fade out within three seconds. Call from viewDidLoad:

[UIView animateWithDuration:3.0 animations:^{myImage.alpha = 0; }];

Or if you want the animation to start at 2.5 seconds and last half a second, you could put that into a method (changing 3.0 to 0.5) and then call:

[NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(hideMyImage) userInfo:nil repeats:no];

Upvotes: 5

roman
roman

Reputation: 11278

Easy as that using core animation

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0f];
imageView.alpha = 0.0f;
[UIView commitAnimations];

if you dont want to slowly fade within 3 seconds, you can use

[UIView setAnimationDelay:3];

and reduce the animation duraction to 0.5f or something. i think using a short fade out time feels better than just simply set hide to YES

Upvotes: 10

adpalumbo
adpalumbo

Reputation: 3031

Are you showing your UIImage in a UIImageView?

If so, just set the hidden property on that image view to YES and the image view (with its image) will disappear.

Upvotes: 1

Related Questions