From ab6dc8577cc36d2a5039b034a077b443d94fe620 Mon Sep 17 00:00:00 2001 From: Troels Richter Date: Wed, 2 Jan 2013 22:18:19 +0100 Subject: [PATCH 1/5] noticeview with is calculated from the view bounds instead of frame to fix orientation with error --- NoticeView/WBNoticeView/WBErrorNoticeView.m | 2 +- NoticeView/WBNoticeView/WBStickyNoticeView.m | 2 +- NoticeView/WBNoticeView/WBSuccessNoticeView.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NoticeView/WBNoticeView/WBErrorNoticeView.m b/NoticeView/WBNoticeView/WBErrorNoticeView.m index bacee44..c344c64 100644 --- a/NoticeView/WBNoticeView/WBErrorNoticeView.m +++ b/NoticeView/WBNoticeView/WBErrorNoticeView.m @@ -25,7 +25,7 @@ - (void)show { // Obtain the screen width - CGFloat viewWidth = self.view.frame.size.width; + CGFloat viewWidth = self.view.bounds.size.width; // Locate the images NSString *path = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"NoticeView.bundle"]; diff --git a/NoticeView/WBNoticeView/WBStickyNoticeView.m b/NoticeView/WBNoticeView/WBStickyNoticeView.m index 8b5aa07..990ecfa 100644 --- a/NoticeView/WBNoticeView/WBStickyNoticeView.m +++ b/NoticeView/WBNoticeView/WBStickyNoticeView.m @@ -24,7 +24,7 @@ - (void)show { // Obtain the screen width - CGFloat viewWidth = self.view.frame.size.width; + CGFloat viewWidth = self.view.bounds.size.width; // Locate the images NSString *path = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"NoticeView.bundle"]; diff --git a/NoticeView/WBNoticeView/WBSuccessNoticeView.m b/NoticeView/WBNoticeView/WBSuccessNoticeView.m index 5519c39..7a8f421 100644 --- a/NoticeView/WBNoticeView/WBSuccessNoticeView.m +++ b/NoticeView/WBNoticeView/WBSuccessNoticeView.m @@ -24,7 +24,7 @@ - (void)show { // Obtain the screen width - CGFloat viewWidth = self.view.frame.size.width; + CGFloat viewWidth = self.view.bounds.size.width; // Locate the images NSString *path = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"NoticeView.bundle"]; From b4812070ee7c84a3165ce2ee49e905327c409f04 Mon Sep 17 00:00:00 2001 From: Troels Richter Date: Wed, 2 Jan 2013 22:50:57 +0100 Subject: [PATCH 2/5] WBNoticeViewSlidingMode property introduced to support for sliding up from the bottom --- NoticeView/WBNoticeView/WBErrorNoticeView.m | 2 +- NoticeView/WBNoticeView/WBNoticeView.h | 13 +++++++++++++ NoticeView/WBNoticeView/WBNoticeView.m | 6 ++++++ NoticeView/WBNoticeView/WBStickyNoticeView.m | 3 +-- NoticeView/WBNoticeView/WBSuccessNoticeView.m | 3 +-- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/NoticeView/WBNoticeView/WBErrorNoticeView.m b/NoticeView/WBNoticeView/WBErrorNoticeView.m index c344c64..b8d272c 100644 --- a/NoticeView/WBNoticeView/WBErrorNoticeView.m +++ b/NoticeView/WBNoticeView/WBErrorNoticeView.m @@ -79,7 +79,7 @@ noticeViewHeight += 30.0; // Make sure we hide completely the view, including its shadow - float hiddenYOrigin = -noticeViewHeight - 20.0; + float hiddenYOrigin = self.slidingMode == WBNoticeViewSlidingModeDown ? -noticeViewHeight - 20.0: self.view.bounds.size.height; // Make and add the notice view self.gradientView = [[WBRedGradientView alloc] initWithFrame:CGRectMake(0.0, hiddenYOrigin, viewWidth, noticeViewHeight + 10.0)]; diff --git a/NoticeView/WBNoticeView/WBNoticeView.h b/NoticeView/WBNoticeView/WBNoticeView.h index 6208a96..2510477 100644 --- a/NoticeView/WBNoticeView/WBNoticeView.h +++ b/NoticeView/WBNoticeView/WBNoticeView.h @@ -8,6 +8,11 @@ #import +typedef enum WBNoticeViewSlidingMode { + WBNoticeViewSlidingModeUp, + WBNoticeViewSlidingModeDown, +} WBNoticeViewSlidingMode; + /** `WBNoticeView` objects provides a lightweight, non-intrusive means for displaying information to the user. The `WBNoticeView` class is an abstract class that encapsulates the interface common to all notice objects. */ @@ -91,6 +96,14 @@ */ @property (nonatomic, readwrite, getter = isSticky) BOOL sticky; +/** + Decides if the notice is shown sliding up from the bottom or down from the top + + **Default**: 'WBNoticeViewSlidingModeDown' +*/ +@property WBNoticeViewSlidingMode slidingMode; + + ///---------------------------------------- /// @name Showing and Dismissing the Notice ///---------------------------------------- diff --git a/NoticeView/WBNoticeView/WBNoticeView.m b/NoticeView/WBNoticeView/WBNoticeView.m index f2303d4..d4d3307 100644 --- a/NoticeView/WBNoticeView/WBNoticeView.m +++ b/NoticeView/WBNoticeView/WBNoticeView.m @@ -55,6 +55,7 @@ self.alpha = 1.0; self.delay = 2.0; self.tapToDismissEnabled = YES; + self.slidingMode = WBNoticeViewSlidingModeDown; } return self; } @@ -92,6 +93,11 @@ [self.gradientView addSubview:button]; } + //set default originY if WBNoticeViewSlidingModeUp + if ((self.slidingMode == WBNoticeViewSlidingModeUp) && (self.originY == 0)) { + self.originY = self.view.bounds.size.height - self.gradientView.bounds.size.height; + } + // Go ahead, display it [UIView animateWithDuration:self.duration animations:^ { CGRect newFrame = self.gradientView.frame; diff --git a/NoticeView/WBNoticeView/WBStickyNoticeView.m b/NoticeView/WBNoticeView/WBStickyNoticeView.m index 990ecfa..66b651e 100644 --- a/NoticeView/WBNoticeView/WBStickyNoticeView.m +++ b/NoticeView/WBNoticeView/WBStickyNoticeView.m @@ -50,13 +50,12 @@ // Calculate the notice view height float noticeViewHeight = 40.0; - float hiddenYOrigin = 0.0; if (numberOfLines > 1) { noticeViewHeight += (numberOfLines - 1) * messageLineHeight; } // Make sure we hide completely the view, including its shadow - hiddenYOrigin = -noticeViewHeight - 20.0; + float hiddenYOrigin = self.slidingMode == WBNoticeViewSlidingModeDown ? -noticeViewHeight - 20.0: self.view.bounds.size.height; // Make and add the notice view self.gradientView = [[WBGrayGradientView alloc] initWithFrame:CGRectMake(0.0, hiddenYOrigin, viewWidth, 32)]; diff --git a/NoticeView/WBNoticeView/WBSuccessNoticeView.m b/NoticeView/WBNoticeView/WBSuccessNoticeView.m index 7a8f421..1c45d49 100644 --- a/NoticeView/WBNoticeView/WBSuccessNoticeView.m +++ b/NoticeView/WBNoticeView/WBSuccessNoticeView.m @@ -45,13 +45,12 @@ // Calculate the notice view height float noticeViewHeight = 40.0; - float hiddenYOrigin = 0.0; if (numberOfLines > 1) { noticeViewHeight += (numberOfLines - 1) * messageLineHeight; } // Make sure we hide completely the view, including its shadow - hiddenYOrigin = -noticeViewHeight - 20.0; + float hiddenYOrigin = self.slidingMode == WBNoticeViewSlidingModeDown ? -noticeViewHeight - 20.0: self.view.bounds.size.height; // Make and add the notice view self.gradientView = [[WBBlueGradientView alloc] initWithFrame:CGRectMake(0.0, hiddenYOrigin, viewWidth, noticeViewHeight + 10.0)]; From bb47295f5f3ab217a33f7875235a6f4db2231605 Mon Sep 17 00:00:00 2001 From: Troels Richter Date: Thu, 3 Jan 2013 07:36:47 +0100 Subject: [PATCH 3/5] there should never be a delay when notice is dismissed interactively. Fixed the case where you wanted to dismiss a non sticky notice interactively --- NoticeView/WBNoticeView/WBNoticeView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NoticeView/WBNoticeView/WBNoticeView.m b/NoticeView/WBNoticeView/WBNoticeView.m index d4d3307..8a87845 100644 --- a/NoticeView/WBNoticeView/WBNoticeView.m +++ b/NoticeView/WBNoticeView/WBNoticeView.m @@ -148,7 +148,7 @@ // Clear the reference to the dismissal block so that the animation does invoke the block a second time self.dismissalBlock = nil; } - [self dismissNoticeWithDuration:self.duration delay:self.delay hiddenYOrigin:self.hiddenYOrigin]; + [self dismissNoticeWithDuration:self.duration delay:0 hiddenYOrigin:self.hiddenYOrigin]; } - (void)dismissAfterTimerExpiration From c06f1d29f5080d9698922e26a0bc851de944e41c Mon Sep 17 00:00:00 2001 From: Troels Richter Date: Sat, 5 Jan 2013 22:16:01 +0100 Subject: [PATCH 4/5] ios5 special handling of notice height removed because it resultet in a higher view than else so that success and notice height differed on ios6 --- NoticeView/WBNoticeView/WBErrorNoticeView.m | 25 +++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/NoticeView/WBNoticeView/WBErrorNoticeView.m b/NoticeView/WBNoticeView/WBErrorNoticeView.m index b8d272c..3fff5d3 100644 --- a/NoticeView/WBNoticeView/WBErrorNoticeView.m +++ b/NoticeView/WBNoticeView/WBErrorNoticeView.m @@ -59,21 +59,16 @@ r.origin.y = self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height; float noticeViewHeight = 0.0; - double currOsVersion = [[[UIDevice currentDevice]systemVersion]doubleValue]; - if (currOsVersion >= 6.0f) { - noticeViewHeight = messageLabelHeight; - } else { - // Now we can determine the height of one line of text - r.size.height = self.messageLabel.frame.size.height * numberOfLines; - r.size.width = viewWidth - 70.0; - self.messageLabel.frame = r; - - // Calculate the notice view height - noticeViewHeight = 10.0; - if (numberOfLines > 1) { - noticeViewHeight += ((numberOfLines - 1) * messageLabelHeight); - } - } + // Now we can determine the height of one line of text + r.size.height = self.messageLabel.frame.size.height * numberOfLines; + r.size.width = viewWidth - 70.0; + self.messageLabel.frame = r; + + // Calculate the notice view height + noticeViewHeight = 10.0; + if (numberOfLines > 1) { + noticeViewHeight += ((numberOfLines - 1) * messageLabelHeight); + } // Add some bottom margin for the notice view noticeViewHeight += 30.0; From 6a548abf777b93b787657f16e5f43eca9c22b9c2 Mon Sep 17 00:00:00 2001 From: Troels Richter Date: Sun, 20 Jan 2013 16:21:25 +0100 Subject: [PATCH 5/5] error fixed: gradient view is redrawn to fit width if notice view is visible while the device is rotated error fixed: sometimes the notice view was never dismissed if the app resigned active while a notice where shown --- NoticeView/WBNoticeView/WBBlueGradientView.m | 1 + NoticeView/WBNoticeView/WBGrayGradientView.m | 1 + NoticeView/WBNoticeView/WBNoticeView.m | 35 +++++++++++--------- NoticeView/WBNoticeView/WBRedGradientView.m | 1 + 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/NoticeView/WBNoticeView/WBBlueGradientView.m b/NoticeView/WBNoticeView/WBBlueGradientView.m index 2c66266..5160646 100644 --- a/NoticeView/WBNoticeView/WBBlueGradientView.m +++ b/NoticeView/WBNoticeView/WBBlueGradientView.m @@ -30,6 +30,7 @@ nil]; [self.layer insertSublayer:gradient atIndex:0]; + self.layer.needsDisplayOnBoundsChange = YES; UIView *firstTopBlueLine = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, self.bounds.size.width, 1.0)]; firstTopBlueLine.backgroundColor = [UIColor colorWithRed:105/255.0f green:163/255.0f blue:208/255.0f alpha:1.0]; diff --git a/NoticeView/WBNoticeView/WBGrayGradientView.m b/NoticeView/WBNoticeView/WBGrayGradientView.m index 3673fd3..ae2eefe 100644 --- a/NoticeView/WBNoticeView/WBGrayGradientView.m +++ b/NoticeView/WBNoticeView/WBGrayGradientView.m @@ -29,6 +29,7 @@ nil]; [self.layer insertSublayer:gradient atIndex:0]; + self.layer.needsDisplayOnBoundsChange = YES; UIView *firstBotWhiteLine = [[UIView alloc]initWithFrame:CGRectMake(0.0, self.bounds.size.height - 1, self.frame.size.width, 1.0)]; firstBotWhiteLine.backgroundColor = [UIColor colorWithRed:236/255.0f green:238/255.0f blue:239/255.0f alpha:1.0]; diff --git a/NoticeView/WBNoticeView/WBNoticeView.m b/NoticeView/WBNoticeView/WBNoticeView.m index 8a87845..f5d6a35 100644 --- a/NoticeView/WBNoticeView/WBNoticeView.m +++ b/NoticeView/WBNoticeView/WBNoticeView.m @@ -96,6 +96,10 @@ //set default originY if WBNoticeViewSlidingModeUp if ((self.slidingMode == WBNoticeViewSlidingModeUp) && (self.originY == 0)) { self.originY = self.view.bounds.size.height - self.gradientView.bounds.size.height; + self.gradientView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth; + } else + { + self.gradientView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth; } // Go ahead, display it @@ -105,15 +109,13 @@ self.gradientView.frame = newFrame; self.gradientView.alpha = self.alpha; } completion:^ (BOOL finished) { - if (finished) { - // if it's not sticky, hide it automatically - if (self.tapToDismissEnabled && !self.isSticky) { - // Schedule a timer - self.displayTimer = [NSTimer scheduledTimerWithTimeInterval:self.delay target:self selector:@selector(dismissAfterTimerExpiration) userInfo:nil repeats:NO]; - } else if (!self.isSticky) { - // Display for a while, then hide it again - [self dismissNoticeWithDuration:self.duration delay:self.delay hiddenYOrigin:self.hiddenYOrigin]; - } + // if it's not sticky, hide it automatically + if (self.tapToDismissEnabled && !self.isSticky) { + // Schedule a timer + self.displayTimer = [NSTimer scheduledTimerWithTimeInterval:self.delay target:self selector:@selector(dismissAfterTimerExpiration) userInfo:nil repeats:NO]; + } else if (!self.isSticky) { + // Display for a while, then hide it again + [self dismissNoticeWithDuration:self.duration delay:self.delay hiddenYOrigin:self.hiddenYOrigin]; } }]; } @@ -122,14 +124,17 @@ { [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseOut animations:^ { CGRect newFrame = self.gradientView.frame; - newFrame.origin.y = hiddenYOrigin; + if (self.slidingMode == WBNoticeViewSlidingModeUp) { + newFrame.origin.y = self.gradientView.frame.origin.y + self.gradientView.bounds.size.height; + } else + { + newFrame.origin.y = hiddenYOrigin; + } self.gradientView.frame = newFrame; } completion:^ (BOOL finished) { - if (finished) { - if (self.dismissalBlock) self.dismissalBlock(NO); - // Cleanup - [self cleanup]; - } + if (self.dismissalBlock) self.dismissalBlock(NO); + // Cleanup + [self cleanup]; }]; } diff --git a/NoticeView/WBNoticeView/WBRedGradientView.m b/NoticeView/WBNoticeView/WBRedGradientView.m index 8477528..8a98a5b 100644 --- a/NoticeView/WBNoticeView/WBRedGradientView.m +++ b/NoticeView/WBNoticeView/WBRedGradientView.m @@ -30,6 +30,7 @@ nil]; [self.layer insertSublayer:gradient atIndex:0]; + self.layer.needsDisplayOnBoundsChange = YES; UIView *firstTopPinkLine = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, self.bounds.size.width, 1.0)]; firstTopPinkLine.backgroundColor = [UIColor colorWithRed:211/255.0f green:82/255.0f blue:80/255.0f alpha:1.0];