mirror of
https://github.com/zhigang1992/NoticeView.git
synced 2026-01-12 17:32:41 +08:00
Merge pull request #32 from troelsrichter/master
WBNoticeViewSlidingMode introduced + bug fixes
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -59,27 +59,22 @@
|
||||
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;
|
||||
|
||||
// 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)];
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
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
|
||||
///----------------------------------------
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
self.alpha = 1.0;
|
||||
self.delay = 2.0;
|
||||
self.tapToDismissEnabled = YES;
|
||||
self.slidingMode = WBNoticeViewSlidingModeDown;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -92,6 +93,15 @@
|
||||
[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;
|
||||
self.gradientView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
|
||||
} else
|
||||
{
|
||||
self.gradientView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
|
||||
}
|
||||
|
||||
// Go ahead, display it
|
||||
[UIView animateWithDuration:self.duration animations:^ {
|
||||
CGRect newFrame = self.gradientView.frame;
|
||||
@@ -105,15 +115,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 +130,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];
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -148,7 +159,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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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)];
|
||||
|
||||
@@ -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)];
|
||||
|
||||
Reference in New Issue
Block a user