user5214391
user5214391

Reputation: 69

How to change UIImageView with some Transition

I am making an image editor application.

I am able to change the UIImage of a UIImageView but I want it to be more efficient and beautiful.

Currently I am changing UIImage as

if(image)
  {
     userImageView.image = image;
  }

It directly changes the UIImage. How can I make a fadeIn-fadeOut effect?

Upvotes: 1

Views: 822

Answers (3)

pradip rathod
pradip rathod

Reputation: 368

try this...

 - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    self.fadeDuration=1;
}
return self;
}
-(void)setImage:(UIImage *)newImage{

if(!self.image||self.fadeDuration<=0){
    super.image=newImage;
} else {
    UIImageView *iv=[[UIImageView alloc] initWithFrame:self.bounds];
    iv.contentMode=self.contentMode;
    iv.image=super.image;
    iv.alpha=1;
    [self addSubview:iv];
    super.image=newImage;
    [UIView animateWithDuration:self.fadeDuration delay:0       options:UIViewAnimationCurveEaseInOut animations:^{
        iv.alpha=0;
    } completion:^(BOOL finished) {
        [iv removeFromSuperview];
    }];
     }
    }

Upvotes: 1

Rahul
Rahul

Reputation: 5844

 UIImage *image = [UIImage imageWithData:imageData];
 [UIView transitionWithView:YourUIImageView
                              duration:2.0f
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                YourUIImageView.image = image;
                            } completion:nil]; 

And Do some googling before asking this question already has and answer.

Check THIs

Upvotes: 1

Wyetro
Wyetro

Reputation: 8588

Try something like this:

-(void)fade{

    //fade out
    [UIView animateWithDuration:1.0f animations:^{

        [userImageView setAlpha:0.0f];

    } completion:^(BOOL finished) {

        //fade in
        [UIView animateWithDuration:1.0f animations:^{
            userImageView.image = image;
            [userImageView setAlpha:1.0f];

        } completion:nil];

    }];
}

Upvotes: 0

Related Questions