Skip to content

Commit

Permalink
do not perform animation on image if the new image is the same
Browse files Browse the repository at this point in the history
  • Loading branch information
ettore committed Mar 16, 2013
1 parent 64b0757 commit 03a7877
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
10 changes: 5 additions & 5 deletions CLCGCell.h
Expand Up @@ -63,12 +63,12 @@
id mContext; id mContext;
} }


@property(nonatomic,retain) NSString *imgUrl; @property(nonatomic,copy) NSString *imgUrl;
@property(nonatomic,assign) BOOL emphasized; @property(nonatomic,assign) BOOL emphasized;
@property(nonatomic,retain) id context;//should this be assign? @property(nonatomic,retain) id context;//should this be assign?
@property(nonatomic,readonly) CGFloat padding; @property(nonatomic,readonly) CGFloat padding;
@property(nonatomic,retain) UILabel *infoTextLabel; @property(nonatomic,retain) UILabel *infoTextLabel;
@property(nonatomic,retain) UIColor *normalColor; @property(nonatomic,retain) UIColor *normalColor;


/*! /*!
The designated initializer. The designated initializer.
Expand Down
19 changes: 12 additions & 7 deletions CLCGCell.m
Expand Up @@ -184,14 +184,19 @@ -(void)showImage:(UIImage*)img
[self setNeedsLayout]; //layout will happen in next update cycle [self setNeedsLayout]; //layout will happen in next update cycle


[[self imageView] setImage:img]; [[self imageView] setImage:img];


// smooth out the appearance of the image a bit
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
CALayer *layer = [[self imageView] layer]; CALayer *layer = [[self imageView] layer];
[anim setDuration:0.2]; //0.2 sec
[anim setFromValue:[NSNumber numberWithFloat:0.0]]; // smooth out the appearance of the image a bit but only if we are changing
[anim setToValue:[NSNumber numberWithFloat:1.0]]; // the image content. No need to animate if the image is the same.
[layer addAnimation:anim forKey:@"animateOpacity"]; if ([[self imageView] image] != img) {
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
[anim setDuration:0.2]; //0.2 sec
[anim setFromValue:[NSNumber numberWithFloat:0.0]];
[anim setToValue:[NSNumber numberWithFloat:1.0]];
[layer addAnimation:anim forKey:@"animateOpacity"];
}

[layer setOpacity:1.0]; //makes the animation ending value stick [layer setOpacity:1.0]; //makes the animation ending value stick
} }


Expand Down

0 comments on commit 03a7877

Please sign in to comment.