Skip to content

Commit

Permalink
Merge pull request #3655 from vishalduggal/timob-11181
Browse files Browse the repository at this point in the history
[TIMOB-11181] Fix gradientLayer animations
  • Loading branch information
Max Stepanov committed Jan 14, 2013
2 parents 7730d6d + 07e47e9 commit 601a6de
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
41 changes: 41 additions & 0 deletions iphone/Classes/TiAnimation.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ -(NSTimeInterval)animationDuration
return animationDuration;
}

-(CAMediaTimingFunction*) timingFunction
{
switch ([curve intValue]) {
case UIViewAnimationOptionCurveEaseInOut: return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
case UIViewAnimationOptionCurveEaseIn: return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
case UIViewAnimationOptionCurveEaseOut: return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
case UIViewAnimationOptionCurveLinear: return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
default: return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
}
}

-(void)animate:(id)args
{
ENSURE_UI_THREAD(animate,args);
Expand Down Expand Up @@ -493,7 +504,37 @@ -(void)animate:(id)args

if (doReposition)
{
CABasicAnimation *boundsAnimation = nil;
CABasicAnimation *positionAnimation = nil;
bool hasGradient = ([uiview gradientLayer] != nil);
if (hasGradient) {
boundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
boundsAnimation.fromValue = [NSValue valueWithCGRect:[uiview bounds]];
boundsAnimation.duration = animationDuration;
boundsAnimation.timingFunction = [self timingFunction];

positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
positionAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake([uiview bounds].size.width / 2, [uiview bounds].size.height / 2)];
positionAnimation.duration = animationDuration;
positionAnimation.timingFunction = [self timingFunction];
}

[(TiViewProxy *)[uiview proxy] reposition];

if (hasGradient) {
boundsAnimation.toValue = [NSValue valueWithCGRect:[uiview bounds]];
positionAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake([uiview bounds].size.width / 2, [uiview bounds].size.height / 2)];
if (repeatCount > 0) {
boundsAnimation.autoreverses = (reverseAnimation != nil);
boundsAnimation.repeatCount = repeatCount;

positionAnimation.autoreverses = (reverseAnimation != nil);
positionAnimation.repeatCount = repeatCount;
}

[[uiview gradientLayer] addAnimation:boundsAnimation forKey:@"animateBounds"];
[[uiview gradientLayer] addAnimation:positionAnimation forKey:@"animatePosition"];
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion iphone/Classes/TiUIView.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ void ModifyScrollViewForKeyboardHeightAndContentHeightWithResponderRect(UIScroll
- (UIGestureRecognizer *)gestureRecognizerForEvent:(NSString *)event;

/**
Returns CA layer for the background of the view.
Returns CA layer for the background image of the view.
*/
-(CALayer *)backgroundImageLayer;
/**
Returns CA layer for the background gradient of the view.
*/
-(CALayer *)gradientLayer;

/**
Tells the view to start specified animation.
Expand Down
5 changes: 5 additions & 0 deletions iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ -(CALayer *)backgroundImageLayer
return [self layer];
}

-(CALayer *)gradientLayer
{
return gradientLayer;
}

// You might wonder why we don't just use the native feature of -[UIColor colorWithPatternImage:].
// Here's why:
// * It doesn't properly handle alpha channels
Expand Down

0 comments on commit 601a6de

Please sign in to comment.