Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-11335] Animate gradientLayer opacity #3661

Merged
merged 1 commit into from
Jan 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
-(void) setBackgroundGradient_:(TiGradient *)newGradient;
-(void) setSelectedBackgroundGradient_:(TiGradient *)newGradient;

-(void) updateGradientLayer:(BOOL)useSelected;
-(void) updateGradientLayer:(BOOL)useSelected withAnimation:(BOOL)animated;
-(CGSize)computeCellSize;

@end
Expand Down
23 changes: 15 additions & 8 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ -(BOOL) selectedOrHighlighted
}


-(void) updateGradientLayer:(BOOL)useSelected
-(void) updateGradientLayer:(BOOL)useSelected withAnimation:(BOOL)animated
{
TiGradient * currentGradient = useSelected?selectedBackgroundGradient:backgroundGradient;

Expand All @@ -200,7 +200,7 @@ -(void) updateGradientLayer:(BOOL)useSelected
//Because there's the chance that the other state still has the gradient, let's keep it around.
return;
}

CALayer * ourLayer = [self layer];

if(gradientLayer == nil)
Expand All @@ -222,31 +222,38 @@ -(void) updateGradientLayer:(BOOL)useSelected
[[self textLabel] setBackgroundColor:[UIColor clearColor]];
}
}
if (animated) {
CABasicAnimation *flash = [CABasicAnimation animationWithKeyPath:@"opacity"];
flash.fromValue = [NSNumber numberWithFloat:0.0];
flash.toValue = [NSNumber numberWithFloat:1.0];
flash.duration = 1.0;
[gradientLayer addAnimation:flash forKey:@"flashAnimation"];
}
[gradientLayer setNeedsDisplay];
}

-(void)setSelected:(BOOL)yn animated:(BOOL)animated
{
[super setSelected:yn animated:animated];
[self updateGradientLayer:yn|[self isHighlighted]];
[self updateGradientLayer:yn|[self isHighlighted] withAnimation:animated];
}

-(void)setHighlighted:(BOOL)yn animated:(BOOL)animated
{
[super setHighlighted:yn animated:animated];
[self updateGradientLayer:yn|[self isSelected]];
[self updateGradientLayer:yn|[self isSelected] withAnimation:animated];
}

-(void)setHighlighted:(BOOL)yn
{
[super setHighlighted:yn];
[self updateGradientLayer:yn|[self isHighlighted]];
[self updateGradientLayer:yn|[self isSelected] withAnimation:NO];
}

-(void)setSelected:(BOOL)yn
{
[super setSelected:yn];
[self updateGradientLayer:yn|[self isHighlighted]];
[self updateGradientLayer:yn|[self isHighlighted] withAnimation:NO];
}

-(void) setBackgroundGradient_:(TiGradient *)newGradient
Expand All @@ -260,7 +267,7 @@ -(void) setBackgroundGradient_:(TiGradient *)newGradient

if(![self selectedOrHighlighted])
{
[self updateGradientLayer:NO];
[self updateGradientLayer:NO withAnimation:NO];
}
}

Expand All @@ -275,7 +282,7 @@ -(void) setSelectedBackgroundGradient_:(TiGradient *)newGradient

if([self selectedOrHighlighted])
{
[self updateGradientLayer:YES];
[self updateGradientLayer:YES withAnimation:NO];
}
}

Expand Down