swiftcode
swiftcode

Reputation: 3059

Fade image from black in UIImageView?

I'm using the SDWebImage framework to load an image from the web asynchronously, and I'm trying to get fading to work. I have it currently fading from white to the image, as such (long animation speed for testing):

self.pictureImageView.alpha = 0.0f;
        [UIView transitionWithView:nil
                          duration:5.0f
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^{
                            [self loadImage:urlForPic];
                            self.pictureImageView.alpha = 1.0f;
                        } completion:nil];

In loadImage: I just do this:

if(urlForPic)
        [self.pictureImageView setImageWithURL:urlForPic
                              placeholderImage:nil];

In my storyboard, I have the background of the UIImageView set to black, and its alpha to 1.0 and opaque checked. If I don't load any image, when loading my view controller it shows up with a black background, as intended. However, as soon as I set an image and do the animation, it fades from white to the image, which I don't want.

Is there a way to have it fade from black to the image with a cross dissolve animation?

Upvotes: 1

Views: 969

Answers (1)

user2329093
user2329093

Reputation:

If you set the view (or container view) background color of black, the animation would look like a fade from black.

Upvotes: 3

Related Questions