Skip to content
Browse files

do not perform animation on image if the new image is the same

  • Loading branch information...
1 parent 64b0757 commit 03a787723fb17620415b31684b3d6ba356bb6fc1 @ettore committed Mar 15, 2013
Showing with 17 additions and 12 deletions.
  1. +5 −5 CLCGCell.h
  2. +12 −7 CLCGCell.m
View
10 CLCGCell.h
@@ -63,12 +63,12 @@
id mContext;
}
-@property(nonatomic,retain) NSString *imgUrl;
-@property(nonatomic,assign) BOOL emphasized;
-@property(nonatomic,retain) id context;//should this be assign?
+@property(nonatomic,copy) NSString *imgUrl;
+@property(nonatomic,assign) BOOL emphasized;
+@property(nonatomic,retain) id context;//should this be assign?
@property(nonatomic,readonly) CGFloat padding;
-@property(nonatomic,retain) UILabel *infoTextLabel;
-@property(nonatomic,retain) UIColor *normalColor;
+@property(nonatomic,retain) UILabel *infoTextLabel;
+@property(nonatomic,retain) UIColor *normalColor;
/*!
The designated initializer.
View
19 CLCGCell.m
@@ -184,14 +184,19 @@ -(void)showImage:(UIImage*)img
[self setNeedsLayout]; //layout will happen in next update cycle
[[self imageView] setImage:img];
-
- // smooth out the appearance of the image a bit
- CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
+
CALayer *layer = [[self imageView] layer];
- [anim setDuration:0.2]; //0.2 sec
- [anim setFromValue:[NSNumber numberWithFloat:0.0]];
- [anim setToValue:[NSNumber numberWithFloat:1.0]];
- [layer addAnimation:anim forKey:@"animateOpacity"];
+
+ // smooth out the appearance of the image a bit but only if we are changing
+ // the image content. No need to animate if the image is the same.
+ 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
}

0 comments on commit 03a7877

Please sign in to comment.
Something went wrong with that request. Please try again.