From 6b91e45a57a969db59e7429a9d871c0438764c72 Mon Sep 17 00:00:00 2001 From: Jason Marziani Date: Wed, 6 Mar 2013 16:27:07 -0500 Subject: [PATCH] FIX: NSRunLoop issue where animations would not fire until after NSEventTrackingRunLoopMode completed, as when a UITableView or UIScrollView is scrolling. Added support for NSRunLoopCommonModes in calls to performSelector and with the NSTimer. --- lib/PRTween.m | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/PRTween.m b/lib/PRTween.m index e8b39af..404d9db 100755 --- a/lib/PRTween.m +++ b/lib/PRTween.m @@ -277,7 +277,7 @@ + (PRTweenOperation *)tween:(id)object property:(NSString*)property from:(CGFloa 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]; + [[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; return operation; } @@ -293,7 +293,7 @@ + (PRTweenOperation *)tween:(CGFloat *)ref from:(CGFloat)from to:(CGFloat)to dur operation.boundRef = ref; [operation addObserver:[PRTween sharedInstance] forKeyPath:@"period.tweenedValue" options:NSKeyValueObservingOptionNew context:NULL]; - [[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0]; + [[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; return operation; } @@ -319,7 +319,7 @@ + (PRTweenOperation *)lerp:(id)object property:(NSString *)property period:(PRTw 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]; + [[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; return operation; } @@ -338,7 +338,7 @@ + (PRTweenOperation *)tween:(id)object property:(NSString*)property from:(CGFloa 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]; + [[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; return operation; } @@ -354,7 +354,7 @@ + (PRTweenOperation *)tween:(CGFloat *)ref from:(CGFloat)from to:(CGFloat)to dur operation.boundRef = ref; [operation addObserver:[PRTween sharedInstance] forKeyPath:@"period.tweenedValue" options:NSKeyValueObservingOptionNew context:NULL]; - [[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0]; + [[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; return operation; } @@ -372,7 +372,7 @@ + (PRTweenOperation *)lerp:(id)object property:(NSString *)property period:(PRTw 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]; + [[PRTween sharedInstance] performSelector:@selector(addTweenOperation:) withObject:operation afterDelay:0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; return operation; } @@ -426,6 +426,7 @@ - (id)init { timeOffset = 0; if (timer == nil) { timer = [NSTimer scheduledTimerWithTimeInterval:kPRTweenFramerate target:self selector:@selector(update) userInfo:nil repeats:YES]; + [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; } self.defaultTimingFunction = &PRTweenTimingFunctionQuadInOut; } @@ -671,7 +672,7 @@ - (void)update { if (period != nil) { if (target != nil && selector != NULL) { - [target performSelector:selector withObject:period afterDelay:0]; + [target performSelector:selector withObject:period afterDelay:0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; } // Check to see if blocks/GCD are supported @@ -692,7 +693,7 @@ - (void)update { // clean up expired tween operations for (__strong PRTweenOperation *tweenOperation in expiredTweenOperations) { - if (tweenOperation.completeSelector) [tweenOperation.target performSelector:tweenOperation.completeSelector withObject:nil afterDelay:0]; + if (tweenOperation.completeSelector) [tweenOperation.target performSelector:tweenOperation.completeSelector withObject:nil afterDelay:0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; // Check to see if blocks/GCD are supported if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_4_0) { if (tweenOperation.completeBlock != NULL) {