Skip to content

Instantly share code, notes, and snippets.

@mikeseif
Last active December 31, 2015 06:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeseif/7949157 to your computer and use it in GitHub Desktop.
Save mikeseif/7949157 to your computer and use it in GitHub Desktop.
Transition a CGRect to another CGRect by the (CGFloat) ratio provided.
+ (CGFloat)transitionFloat:(CGFloat)float1 toFloat:(CGFloat)float2 byRatio:(CGFloat)ratio
{
return ( ratio * (float2 - float1) );
}
+ (CGRect)transitionRect:(CGRect)rect1 toRect:(CGRect)rect2 byRatio:(CGFloat)ratio
{
if (CGRectIsNull(rect1) || CGRectIsNull(rect2)) {
return CGRectZero;
}
return CGRectMake(
rect1.origin.x + [self transitionFloat:rect1.origin.x toFloat:rect2.origin.x byRatio:ratio],
rect1.origin.y + [self transitionFloat:rect1.origin.y toFloat:rect2.origin.y byRatio:ratio],
rect1.size.width + [self transitionFloat:rect1.size.width toFloat:rect2.size.width byRatio:ratio],
rect1.size.height + [self transitionFloat:rect1.size.height toFloat:rect2.size.height byRatio:ratio]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment