Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New feature: Basic functionality to save/restore state

  • Loading branch information...
commit 35ec5abe8c0fabfb919e33ca3dec9fa83a8174e4 1 parent 9413d5a
@myell0w authored
Showing with 76 additions and 21 deletions.
  1. +18 −7 MTStatusBarOverlay.h
  2. +58 −14 MTStatusBarOverlay.m
View
25 MTStatusBarOverlay.h
@@ -29,9 +29,9 @@
// Animation that happens, when the user touches the status bar overlay
typedef enum MTStatusBarOverlayAnimation {
- MTStatusBarOverlayAnimationNone, // nothing happens
- MTStatusBarOverlayAnimationShrink, // the status bar shrinks to the right side and only shows the activity indicator
- MTStatusBarOverlayAnimationFallDown // the status bar falls down and displays more information
+ MTStatusBarOverlayAnimationNone, // nothing happens
+ MTStatusBarOverlayAnimationShrink, // the status bar shrinks to the right side and only shows the activity indicator
+ MTStatusBarOverlayAnimationFallDown // the status bar falls down and displays more information
} MTStatusBarOverlayAnimation;
@@ -50,16 +50,21 @@ typedef enum MTMessageType {
} MTMessageType;
-// forward-declaration of delegate-protocol
-@protocol MTStatusBarOverlayDelegate;
-
-
+// keys used in the dictionary-representation of a status message
#define kMTStatusBarOverlayMessageKey @"MessageText"
#define kMTStatusBarOverlayMessageTypeKey @"MessageType"
#define kMTStatusBarOverlayDurationKey @"MessageDuration"
#define kMTStatusBarOverlayAnimationKey @"MessageAnimation"
#define kMTStatusBarOverlayImmediateKey @"MessageImmediate"
+// keys used for saving state to NSUserDefaults
+#define kMTStatusBarOverlayStateShrinked @"kMTStatusBarOverlayStateShrinked"
+
+
+// forward-declaration of delegate-protocol
+@protocol MTStatusBarOverlayDelegate;
+
+
//===========================================================
#pragma mark -
@@ -203,6 +208,12 @@ typedef enum MTMessageType {
// hides the status bar overlay
- (void)hide;
+// saves the state in NSUserDefaults and synchronizes them
+- (void)saveState;
+- (void)saveStateSynchronized:(BOOL)synchronizeAtEnd;
+// restores the state from NSUserDefaults
+- (void)restoreState;
+
@end
View
72 MTStatusBarOverlay.m
@@ -323,6 +323,7 @@ - (id)initWithFrame:(CGRect)frame {
backgroundView_ = [[UIView alloc] initWithFrame:statusBarFrame];
backgroundView_.clipsToBounds = YES;
backgroundView_.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+ oldBackgroundViewFrame_ = backgroundView_.frame;
// Add gesture recognizers
UITapGestureRecognizer *tapGestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentViewClicked:)] autorelease];
@@ -423,7 +424,7 @@ - (void)dealloc {
//===========================================================
#pragma mark -
-#pragma mark Change status bar appearance and behavior
+#pragma mark Change status bar appearance
//===========================================================
- (void)addSubviewToBackgroundView:(UIView *)view {
@@ -436,6 +437,35 @@ - (void)addSubviewToBackgroundView:(UIView *)view atIndex:(NSInteger)index {
[self.backgroundView insertSubview:view atIndex:index];
}
+
+//===========================================================
+#pragma mark -
+#pragma mark Save/Restore current state
+//===========================================================
+
+- (void)saveState {
+ [self saveStateSynchronized:YES];
+}
+
+- (void)saveStateSynchronized:(BOOL)synchronizeAtEnd {
+ // TODO: save more state
+ [[NSUserDefaults standardUserDefaults] setBool:self.shrinked forKey:kMTStatusBarOverlayStateShrinked];
+
+ if (synchronizeAtEnd) {
+ [[NSUserDefaults standardUserDefaults] synchronize];
+ }
+}
+
+- (void)restoreState {
+ // restore shrinked-state
+ [self setShrinked:[[NSUserDefaults standardUserDefaults] boolForKey:kMTStatusBarOverlayStateShrinked] animated:NO];
+}
+
+//===========================================================
+#pragma mark -
+#pragma mark Post Messages
+//===========================================================
+
- (void)postMessage:(NSString *)message {
[self postMessage:message animated:YES];
}
@@ -528,6 +558,10 @@ - (void)postImmediateMessage:(NSString *)message type:(MTMessageType)messageType
[self postMessage:message type:messageType duration:duration animated:animated immediate:YES];
}
+//===========================================================
+#pragma mark -
+#pragma mark Show/Hide Status Bar
+//===========================================================
- (void)showNextMessage {
// if there is no next message to show overlay is not active anymore
@@ -962,19 +996,29 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (IBAction)contentViewClicked:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
- switch (self.animation) {
- case MTStatusBarOverlayAnimationShrink:
- [self setShrinked:!self.shrinked animated:YES];
- break;
-
- case MTStatusBarOverlayAnimationFallDown:
- // detailView currently visible -> hide it
- [self setDetailViewHidden:!self.detailViewHidden animated:YES];
- break;
- case MTStatusBarOverlayAnimationNone:
- // ignore
- break;
- }
+
+ // if we are currently in a special state, restore to normal
+ // and ignore current set animation in that case
+ if (self.shrinked) {
+ [self setShrinked:NO animated:YES];
+ } else if (!self.detailViewHidden) {
+ [self setDetailViewHidden:YES animated:NO];
+ } else {
+ // normal case/status, do what's specified in animation-state
+ switch (self.animation) {
+ case MTStatusBarOverlayAnimationShrink:
+ [self setShrinked:!self.shrinked animated:YES];
+ break;
+
+ case MTStatusBarOverlayAnimationFallDown:
+ // detailView currently visible -> hide it
+ [self setDetailViewHidden:!self.detailViewHidden animated:YES];
+ break;
+ case MTStatusBarOverlayAnimationNone:
+ // ignore
+ break;
+ }
+ }
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(statusBarOverlayDidRecognizeGesture:)]) {
[self.delegate statusBarOverlayDidRecognizeGesture:gestureRecognizer];
Please sign in to comment.
Something went wrong with that request. Please try again.