@@ -576,22 +576,38 @@ - (void)scrollAwayWithInterval:(NSTimeInterval)interval delayAmount:(NSTimeInter
576576
577577 __weak __typeof__ (self) weakSelf = self;
578578 self.scrollCompletionBlock = ^(BOOL finished) {
579- if (!finished || !weakSelf) {
580- // Do not continue into the next loop
579+ if (!weakSelf) {
581580 return ;
582581 }
582+
583583 // Call returned home method
584584 [weakSelf labelReturnedToHome: YES ];
585+
585586 // Check to ensure that:
586- // 1) We don't double fire if an animation already exists
587- // 2) The instance is still attached to a window - this completion block is called for
587+ // 1) The instance is still attached to a window - this completion block is called for
588588 // many reasons, including if the animation is removed due to the view being removed
589589 // from the UIWindow (typically when the view controller is no longer the "top" view)
590- if (self.window && ![weakSelf.subLabel.layer animationForKey: @" position" ]) {
591- // Begin again, if conditions met
592- if (weakSelf.labelShouldScroll && !weakSelf.tapToScroll && !weakSelf.holdScrolling ) {
593- [weakSelf scrollAwayWithInterval: interval delayAmount: delayAmount shouldReturn: shouldReturn];
594- }
590+ if (!weakSelf.window ) {
591+ return ;
592+ }
593+ // 2) We don't double fire if an animation already exists
594+ if ([weakSelf.subLabel.layer animationForKey: @" position" ]) {
595+ return ;
596+ }
597+ // 3) We don't not start automatically if the animation was unexpectedly interrupted
598+ if (!finished) {
599+ // Do not continue into the next loop
600+ return ;
601+ }
602+ // 4) A completion block still exists for the NEXT loop. A notable case here is if
603+ // returnLabelToHome was called during a subclass's labelReturnToHome function
604+ if (!weakSelf.scrollCompletionBlock ) {
605+ return ;
606+ }
607+
608+ // Begin again, if conditions met
609+ if (weakSelf.labelShouldScroll && !weakSelf.tapToScroll && !weakSelf.holdScrolling ) {
610+ [weakSelf scrollAwayWithInterval: interval delayAmount: delayAmount shouldReturn: shouldReturn];
595611 }
596612 };
597613
0 commit comments