Browse files

Bug fixes to duration and setter generation

  • Loading branch information...
1 parent d40be5b commit eed17d9d106bd3fbec4abe68b0b686e7dc409aba Dominik Hofmann committed Sep 23, 2011
Showing with 13 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +12 −7 lib/PRTween.m
View
1 .gitignore
@@ -1,2 +1,3 @@
*.xcuserstate
+*.xcuserdatad
.DS_Store
View
19 lib/PRTween.m
@@ -141,7 +141,7 @@ - (void)dealloc {
@implementation PRTweenCGPointLerp
+ (PRTweenOperation *)lerp:(id)object property:(NSString *)property from:(CGPoint)from to:(CGPoint)to duration:(CGFloat)duration timingFunction:(PRTweenTimingFunction)timingFunction target:(NSObject *)target completeSelector:(SEL)selector {
- return [PRTween lerp:object property:property period:[PRTweenCGPointLerpPeriod periodWithStartCGPoint:from endCGPoint:to duration:1] timingFunction:timingFunction target:target completeSelector:selector];
+ return [PRTween lerp:object property:property period:[PRTweenCGPointLerpPeriod periodWithStartCGPoint:from endCGPoint:to duration:duration] timingFunction:timingFunction target:target completeSelector:selector];
}
+ (PRTweenOperation *)lerp:(id)object property:(NSString *)property from:(CGPoint)from to:(CGPoint)to duration:(CGFloat)duration {
@@ -150,7 +150,7 @@ + (PRTweenOperation *)lerp:(id)object property:(NSString *)property from:(CGPoin
#if NS_BLOCKS_AVAILABLE
+ (PRTweenOperation *)lerp:(id)object property:(NSString *)property from:(CGPoint)from to:(CGPoint)to duration:(CGFloat)duration timingFunction:(PRTweenTimingFunction)timingFunction updateBlock:(PRTweenUpdateBlock)updateBlock completeBlock:(PRTweenCompleteBlock)completeBlock {
- return [PRTween lerp:object property:property period:[PRTweenCGPointLerpPeriod periodWithStartCGPoint:from endCGPoint:to duration:1] timingFunction:timingFunction updateBlock:updateBlock completeBlock:completeBlock];
+ return [PRTween lerp:object property:property period:[PRTweenCGPointLerpPeriod periodWithStartCGPoint:from endCGPoint:to duration:duration] timingFunction:timingFunction updateBlock:updateBlock completeBlock:completeBlock];
}
#endif
@@ -159,7 +159,7 @@ + (PRTweenOperation *)lerp:(id)object property:(NSString *)property from:(CGPoin
@implementation PRTweenCGRectLerp
+ (PRTweenOperation *)lerp:(id)object property:(NSString *)property from:(CGRect)from to:(CGRect)to duration:(CGFloat)duration timingFunction:(PRTweenTimingFunction)timingFunction target:(NSObject *)target completeSelector:(SEL)selector {
- return [PRTween lerp:object property:property period:[PRTweenCGRectLerpPeriod periodWithStartCGRect:from endCGRect:to duration:1] timingFunction:timingFunction target:target completeSelector:selector];
+ return [PRTween lerp:object property:property period:[PRTweenCGRectLerpPeriod periodWithStartCGRect:from endCGRect:to duration:duration] timingFunction:timingFunction target:target completeSelector:selector];
}
+ (PRTweenOperation *)lerp:(id)object property:(NSString *)property from:(CGRect)from to:(CGRect)to duration:(CGFloat)duration {
@@ -175,6 +175,7 @@ + (PRTweenOperation *)lerp:(id)object property:(NSString *)property from:(CGRect
@end
@interface PRTween ()
++ (SEL)setterFromProperty:(NSString *)property;
- (void)update;
@end
@@ -204,7 +205,7 @@ + (PRTweenOperation *)tween:(id)object property:(NSString*)property from:(CGFloa
operation.completeSelector = selector;
operation.boundObject = object;
operation.boundGetter = NSSelectorFromString([NSString stringWithFormat:@"%@", property]);
- operation.boundSetter = NSSelectorFromString([NSString stringWithFormat:@"set%@:", [property stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[[property substringToIndex:1] capitalizedString]]]);
+ operation.boundSetter = [PRTween setterFromProperty:property];
[operation addObserver:[PRTween sharedInstance] forKeyPath:@"period.tweenedValue" options:NSKeyValueObservingOptionNew context:NULL];
[[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0];
@@ -244,7 +245,7 @@ + (PRTweenOperation *)lerp:(id)object property:(NSString *)property period:(PRTw
operation.completeSelector = selector;
operation.boundObject = object;
operation.boundGetter = NSSelectorFromString([NSString stringWithFormat:@"%@", property]);
- operation.boundSetter = NSSelectorFromString([NSString stringWithFormat:@"set%@:", [property capitalizedString]]);
+ operation.boundSetter = [PRTween setterFromProperty:property];
[operation addObserver:[PRTween sharedInstance] forKeyPath:@"period.tweenedLerp" options:NSKeyValueObservingOptionNew context:NULL];
[[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0];
@@ -263,7 +264,7 @@ + (PRTweenOperation *)tween:(id)object property:(NSString*)property from:(CGFloa
operation.completeBlock = completeBlock;
operation.boundObject = object;
operation.boundGetter = NSSelectorFromString([NSString stringWithFormat:@"%@", property]);
- operation.boundSetter = NSSelectorFromString([NSString stringWithFormat:@"set%@:", [property capitalizedString]]);
+ operation.boundSetter = [PRTween setterFromProperty:property];
[operation addObserver:[PRTween sharedInstance] forKeyPath:@"period.tweenedValue" options:NSKeyValueObservingOptionNew context:NULL];
[[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0];
@@ -297,7 +298,7 @@ + (PRTweenOperation *)lerp:(id)object property:(NSString *)property period:(PRTw
operation.completeBlock = completeBlock;
operation.boundObject = object;
operation.boundGetter = NSSelectorFromString([NSString stringWithFormat:@"%@", property]);
- operation.boundSetter = NSSelectorFromString([NSString stringWithFormat:@"set%@:", [property capitalizedString]]);
+ operation.boundSetter = [PRTween setterFromProperty:property];
[operation addObserver:[PRTween sharedInstance] forKeyPath:@"period.tweenedLerp" options:NSKeyValueObservingOptionNew context:NULL];
[[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0];
@@ -551,6 +552,10 @@ - (void)removeTweenOperation:(PRTweenOperation *)tweenOperation {
}
}
++ (SEL)setterFromProperty:(NSString *)property {
+ return NSSelectorFromString([NSString stringWithFormat:@"set%@:", [property stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[[property substringToIndex:1] capitalizedString]]]);
+}
+
- (void)update {
timeOffset += kPRTweenFramerate;

0 comments on commit eed17d9

Please sign in to comment.