Skip to content

Commit

Permalink
Added generic bulk-restart class method, and revised location-specifi…
Browse files Browse the repository at this point in the history
…c methods.
  • Loading branch information
cbpowell committed Dec 27, 2013
1 parent d72a18c commit 1c0237f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
46 changes: 31 additions & 15 deletions MarqueeLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,34 @@ typedef NS_ENUM(NSUInteger, MarqueeType) {
/// @name Bulk-manipulation Methods
////////////////////////////////////////////////////////////////////////////////

/** Restarts all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
/** Convenience method to restart all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
This method is intended to be placed in the `viewDidAppear:` method of view controllers, and sends an `NSNotification`
to all `MarqueeLabel` instances with the specified view controller in their next responder chain. These instances
will be automatically restarted.
This method sends a `NSNotification` to all `MarqueeLabel` instances with the specified view controller in their next responder chain.
The scrolling animation of these instances will be automatically restarted. This is equivalent to calling `restartLabel` on all affected
instances.
There is currently no functional difference between this method and `controllerViewDidAppear:` or `controllerViewWillAppear:`. The methods may
be used interchangeably.
@warning View controllers that appear with animation (such as from underneath a modal-style controller) can cause some `MarqueeLabel` text
position "jumping" when this method is used in `viewDidAppear` if scroll animations are already underway. Use this method inside `viewWillAppear:`
instead to avoid this problem.
@warning MarqueeLabel instances in view controllers that appear with animation (such as from underneath a modal-style controller)
may experience some text position jumping when this method is used in `viewDidAppear`. Use `controllerViewWillAppear:` inside your
view controller's `viewWillAppear:` method to avoid this issue. Currently, both methods use the same procedure to restart label
scroll animation.
@warning This method may not function properly if passed the parent view controller when using view controller containment.
@param controller The view controller that has appeared.
@see restartLabel
@see controllerViewDidAppear:
@see controllerViewWillAppear:
@since Available in 1.3.1 and later.
*/

+ (void)restartLabelsOfController:(UIViewController *)controller;


/** Convenience method to restart all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
Alternative to `restartLabelsOfController:`. This method is retained for backwards compatibility and future enhancements.
@param controller The view controller that has appeared.
@see restartLabel
Expand All @@ -271,17 +289,14 @@ typedef NS_ENUM(NSUInteger, MarqueeType) {
+ (void)controllerViewDidAppear:(UIViewController *)controller;


/** Prepares all `MarqueeLabel` instances that have the specified view controller in their next responder chain to restart
the scroll animation, and then automatically restarts scrolling.
/** Convenience method to restart all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
This method is intended to be placed in the `viewDidAppear:` method of view controllers, and sends an `NSNotification`
to all `MarqueeLabel` instances with the specified view controller in their next responder chain. These instances
will be automatically restarted.
Alternative to `restartLabelsOfController:`. This method is retained for backwards compatibility and future enhancements.
@param controller The view controller that has appeared.
@see restartLabel
@see controllerViewDidAppear:
@since Available in 1.2.7 and later.
@since Available in 1.2.8 and later.
*/

+ (void)controllerViewWillAppear:(UIViewController *)controller;
Expand All @@ -297,7 +312,8 @@ typedef NS_ENUM(NSUInteger, MarqueeType) {
@see restartLabel
@deprecated Use `controllerViewDidAppear:` instead.
*/
+ (void)controllerViewAppearing:(UIViewController *)controller __attribute((deprecated("Use controllerViewWillAppear: method")));

+ (void)controllerViewAppearing:(UIViewController *)controller __attribute((deprecated("Use restartLabelsOfController: method")));


/** Labelizes all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
Expand Down
28 changes: 11 additions & 17 deletions MarqueeLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#import "MarqueeLabel.h"
#import <QuartzCore/QuartzCore.h>

NSString *const kMarqueeLabelViewWillAppearNotification = @"MarqueeLabelViewControllerWillAppear";
NSString *const kMarqueeLabelViewDidAppearNotification = @"MarqueeLabelViewControllerDidAppear";
NSString *const kMarqueeLabelControllerRestartNotification = @"MarqueeLabelViewControllerRestart";
NSString *const kMarqueeLabelShouldLabelizeNotification = @"MarqueeLabelShouldLabelizeNotification";
NSString *const kMarqueeLabelShouldAnimateNotification = @"MarqueeLabelShouldAnimateNotification";

Expand Down Expand Up @@ -56,18 +55,21 @@ @implementation MarqueeLabel

#pragma mark - Class Methods and handlers

+ (void)controllerViewWillAppear:(UIViewController *)controller {
+ (void)restartLabelsOfController:(UIViewController *)controller {
[MarqueeLabel notifyController:controller
withMessage:kMarqueeLabelViewWillAppearNotification];
withMessage:kMarqueeLabelControllerRestartNotification];
}

+ (void)controllerViewWillAppear:(UIViewController *)controller {
[MarqueeLabel restartLabelsOfController:controller];
}

+ (void)controllerViewDidAppear:(UIViewController *)controller {
[MarqueeLabel notifyController:controller
withMessage:kMarqueeLabelViewDidAppearNotification];
[MarqueeLabel restartLabelsOfController:controller];
}

+ (void)controllerViewAppearing:(UIViewController *)controller {
[MarqueeLabel controllerViewDidAppear:controller];
[MarqueeLabel restartLabelsOfController:controller];
}

+ (void)controllerLabelsShouldLabelize:(UIViewController *)controller {
Expand All @@ -90,14 +92,7 @@ + (void)notifyController:(UIViewController *)controller withMessage:(NSString *)
}
}

- (void)viewControllerWillAppear:(NSNotification *)notification {
UIViewController *controller = [[notification userInfo] objectForKey:@"controller"];
if (controller == [self firstAvailableViewController]) {
[self restartLabel];
}
}

- (void)viewControllerDidAppear:(NSNotification *)notification {
- (void)viewControllerShouldRestart:(NSNotification *)notification {
UIViewController *controller = [[notification userInfo] objectForKey:@"controller"];
if (controller == [self firstAvailableViewController]) {
[self restartLabel];
Expand Down Expand Up @@ -201,8 +196,7 @@ - (void)setupLabel {

// Add notification observers
// Custom class notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewControllerWillAppear:) name:kMarqueeLabelViewWillAppearNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewControllerDidAppear:) name:kMarqueeLabelViewDidAppearNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewControllerShouldRestart:) name:kMarqueeLabelControllerRestartNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(labelsShouldLabelize:) name:kMarqueeLabelShouldLabelizeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(labelsShouldAnimate:) name:kMarqueeLabelShouldAnimateNotification object:nil];

Expand Down

0 comments on commit 1c0237f

Please sign in to comment.