Skip to content

Commit

Permalink
Added pre- and post-animation hooks for subclass usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbpowell committed May 17, 2014
1 parent 008982d commit 4e7d9bb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
28 changes: 28 additions & 0 deletions MarqueeLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ typedef NS_ENUM(NSUInteger, MarqueeType) {

- (void)pauseLabel;


/** Un-pauses a previously paused text scrolling animation
@see pauseLabel
Expand All @@ -261,6 +262,33 @@ typedef NS_ENUM(NSUInteger, MarqueeType) {
- (void)unpauseLabel;


/** Called when the label animation has finished, and the label is at the home position.
The default implementation of this method does nothing. Subclasses may override this method in order to perform any custom actions before
the label animation begins. This is only called in the event that the conditions for scrolling to begin are met.
@since Available in 1.5.0 and later.
*/

- (void)labelWillBeginScroll;


/** Called when the label animation has finished, and the label is at the home position.
The default implementation of this method does nothing. Subclasses may override this method in order to perform any custom actions after
the label animation is complete, and before the next animation would begin (assuming the conditions are met).
@param A Boolean that indicates whether or not the scroll animation actually finished before the completion handler was called.
@since Available in 1.5.0 and later.
@warning This method will be called, and the `finished` parameter will be `NO`, when any property changes that would cause the label scrolling to be
reset are made. This includes changes to label text and font/font size changes.
*/

- (void)labelReturnedToHome:(BOOL)finished;



////////////////////////////////////////////////////////////////////////////////
/// @name Label States
////////////////////////////////////////////////////////////////////////////////
Expand Down
28 changes: 25 additions & 3 deletions MarqueeLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,13 @@ - (void)scrollAwayWithInterval:(NSTimeInterval)interval delayAmount:(NSTimeInter
return;
}

// Perform animation
self.awayFromHome = YES;

[self.subLabel.layer removeAllAnimations];
[self.layer removeAllAnimations];

// Call pre-animation method
[self labelWillBeginScroll];

// Animate
[UIView animateWithDuration:interval
delay:delayAmount
options:self.animationCurve
Expand All @@ -583,6 +584,9 @@ - (void)scrollAwayWithInterval:(NSTimeInterval)interval delayAmount:(NSTimeInter
[self scrollHomeWithInterval:interval delayAmount:delayAmount];
}
}];

// Move to away state
self.awayFromHome = YES;
}

- (void)scrollHomeWithInterval:(NSTimeInterval)interval {
Expand All @@ -605,9 +609,13 @@ - (void)scrollHomeWithInterval:(NSTimeInterval)interval delayAmount:(NSTimeInter
self.subLabel.frame = self.homeLabelFrame;
}
completion:^(BOOL finished){
// Call completion method
[self labelReturnedToHome:finished];

if (finished) {
// Set awayFromHome
self.awayFromHome = NO;

if (!self.tapToScroll && !self.holdScrolling) {
[self scrollAwayWithInterval:interval];
}
Expand All @@ -633,6 +641,9 @@ - (void)scrollContinuousWithInterval:(NSTimeInterval)interval after:(NSTimeInter

self.awayFromHome = YES;

// Call pre-animation method
[self labelWillBeginScroll];

// Animate
[UIView animateWithDuration:interval
delay:delayAmount
Expand All @@ -646,6 +657,9 @@ - (void)scrollContinuousWithInterval:(NSTimeInterval)interval after:(NSTimeInter
}
}
completion:^(BOOL finished) {
// Call completion method
[self labelReturnedToHome:finished];

if (finished && !self.tapToScroll && !self.holdScrolling) {
self.awayFromHome = NO;
[self scrollContinuousWithInterval:interval after:delayAmount];
Expand Down Expand Up @@ -723,6 +737,14 @@ - (void)labelWasTapped:(UITapGestureRecognizer *)recognizer {
}
}

- (void)labelWillBeginScroll {
return;
}

- (void)labelReturnedToHome:(BOOL)finished {
return;
}

#pragma mark - Modified UILabel Getters/Setters

- (NSString *)text {
Expand Down

0 comments on commit 4e7d9bb

Please sign in to comment.