Fixed #21: Add 'sticky' property to override the default behavior

This commit is contained in:
Tito Ciuro
2012-09-29 14:27:49 -07:00
parent 8a0f1a1ee4
commit 044d97be4c
7 changed files with 89 additions and 28 deletions

View File

@@ -18,6 +18,7 @@
WBErrorNoticeView *notice = [[WBErrorNoticeView alloc]initWithView:view title:title];
notice.message = message;
notice.sticky = NO;
return notice;
}

View File

@@ -25,6 +25,7 @@ typedef enum {
@property (nonatomic, readwrite) CGFloat delay; // default: 2.0
@property (nonatomic, readwrite) CGFloat alpha; // default: 1.0
@property (nonatomic, readwrite) CGFloat originY; // default: 0.0
@property (nonatomic, readwrite, getter = isSticky) BOOL sticky; // default NO (Error and Success notice); YES (Sticky notice)
+ (WBNoticeView *)defaultManager;

View File

@@ -48,15 +48,13 @@
alpha:(float)alpha
yOrigin:(CGFloat)origin;
- (void)displayNoticeOfType:(WBNoticeViewType)noticeType
duration:(CGFloat)duration
- (void)displayNoticeWithDuration:(CGFloat)duration
delay:(CGFloat)delay
origin:(CGFloat)origin
hiddenYOrigin:(CGFloat)hiddenYOrigin
alpha:(CGFloat)alpha;
- (void)dismissNoticeOfType:(WBNoticeViewType)noticeType
duration:(CGFloat)duration
- (void)dismissNoticeWithDuration:(CGFloat)duration
delay:(CGFloat)delay
hiddenYOrigin:(CGFloat)hiddenYOrigin;
@@ -78,6 +76,7 @@
@synthesize delay = _delay;
@synthesize alpha = _alpha;
@synthesize originY = _originY;
@synthesize sticky = _sticky;
+ (WBNoticeView *)defaultManager
{
@@ -242,10 +241,15 @@
if (nil == title) title = @"Unknown Error";
if (nil == message) message = @"Information not provided.";
if (0.0 == duration) duration = 0.5;
if ((0.0 == delay) && (WBNoticeViewTypeSticky != noticeType)) delay = 2.0;
if (0.0 == alpha) alpha = 1.0;
if (origin < 0.0) origin = 0.0;
if (self.isSticky) {
delay = 0.0;
} else {
if (0.0 == delay) delay = 2.0;
}
switch (noticeType) {
case WBNoticeViewTypeError:
[self _showErrorNoticeInView:view title:title message:message duration:duration delay:delay alpha:alpha yOrigin:origin];
@@ -359,7 +363,7 @@
self.alpha = alpha;
self.hiddenYOrigin = hiddenYOrigin;
[self displayNoticeOfType:WBNoticeViewTypeError duration:duration delay:delay origin:origin hiddenYOrigin:hiddenYOrigin alpha:alpha];
[self displayNoticeWithDuration:duration delay:delay origin:origin hiddenYOrigin:hiddenYOrigin alpha:alpha];
}
- (void)_showSuccessNoticeInView:(UIView *)view
@@ -427,7 +431,7 @@
self.alpha = alpha;
self.hiddenYOrigin = hiddenYOrigin;
[self displayNoticeOfType:WBNoticeViewTypeSuccess duration:duration delay:delay origin:origin hiddenYOrigin:hiddenYOrigin alpha:alpha];
[self displayNoticeWithDuration:duration delay:delay origin:origin hiddenYOrigin:hiddenYOrigin alpha:alpha];
}
- (void)_showStickyNoticeInView:(UIView *)view
@@ -502,27 +506,30 @@
noticeLayer.masksToBounds = NO;
noticeLayer.shouldRasterize = YES;
// Add an invisible button that responds to a manual dismiss
self.currentNotice = self;
frame = self.gradientView.frame;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
frame.origin.x = frame.origin.y = 0.0;
button.frame = frame;
[button addTarget:self.currentNotice action:@selector(dismissStickyNotice:) forControlEvents:UIControlEventTouchUpInside];
[self.gradientView addSubview:button];
self.duration = duration;
self.delay = delay;
self.alpha = alpha;
self.hiddenYOrigin = hiddenYOrigin;
[self displayNoticeOfType:WBNoticeViewTypeSticky duration:duration delay:delay origin:origin hiddenYOrigin:hiddenYOrigin alpha:alpha];
[self displayNoticeWithDuration:duration delay:delay origin:origin hiddenYOrigin:hiddenYOrigin alpha:alpha];
}
#pragma mark -
- (void)displayNoticeOfType:(WBNoticeViewType)noticeType duration:(CGFloat)duration delay:(CGFloat)delay origin:(CGFloat)origin hiddenYOrigin:(CGFloat)hiddenYOrigin alpha:(CGFloat)alpha
- (void)displayNoticeWithDuration:(CGFloat)duration delay:(CGFloat)delay origin:(CGFloat)origin hiddenYOrigin:(CGFloat)hiddenYOrigin alpha:(CGFloat)alpha
{
// If the notice is sticky, add tap capabilities
if (self.isSticky) {
// Add an invisible button that responds to a manual dismiss
self.currentNotice = self;
CGRect frame = self.gradientView.frame;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
frame.origin.x = frame.origin.y = 0.0;
button.frame = frame;
[button addTarget:self.currentNotice action:@selector(dismissStickyNotice:) forControlEvents:UIControlEventTouchUpInside];
[self.gradientView addSubview:button];
}
// Go ahead, display it
[UIView animateWithDuration:duration animations:^ {
CGRect newFrame = self.gradientView.frame;
@@ -532,15 +539,15 @@
} completion:^ (BOOL finished) {
if (finished) {
// if it's not sticky, hide it automatically
if (WBNoticeViewTypeSticky != noticeType) {
if (NO == self.isSticky) {
// Display for a while, then hide it again
[self dismissNoticeOfType:noticeType duration:duration delay:delay hiddenYOrigin:hiddenYOrigin];
[self dismissNoticeWithDuration:duration delay:delay hiddenYOrigin:hiddenYOrigin];
}
}
}];
}
- (void)dismissNoticeOfType:(WBNoticeViewType)noticeType duration:(CGFloat)duration delay:(CGFloat)delay hiddenYOrigin:(CGFloat)hiddenYOrigin
- (void)dismissNoticeWithDuration:(CGFloat)duration delay:(CGFloat)delay hiddenYOrigin:(CGFloat)hiddenYOrigin
{
[UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseOut animations:^ {
CGRect newFrame = self.gradientView.frame;
@@ -557,7 +564,7 @@
- (IBAction)dismissStickyNotice:(id)sender
{
// Triggered manually by the sticky notice
[self dismissNoticeOfType:WBNoticeViewTypeSticky duration:self.duration delay:self.delay hiddenYOrigin:self.hiddenYOrigin];
[self dismissNoticeWithDuration:self.duration delay:self.delay hiddenYOrigin:self.hiddenYOrigin];
}
#pragma mark -

View File

@@ -17,6 +17,8 @@
{
WBStickyNoticeView *notice = [[WBStickyNoticeView alloc]initWithView:view title:title];
notice.sticky = YES;
return notice;
}

View File

@@ -17,6 +17,8 @@
{
WBSuccessNoticeView *notice = [[WBSuccessNoticeView alloc]initWithView:view title:title];
notice.sticky = NO;
return notice;
}

View File

@@ -143,4 +143,20 @@
[self.navigationController pushViewController: [[WBViewController alloc] init] animated:YES];
}
- (IBAction)showStickyError:(id)sender
{
WBErrorNoticeView *notice = [WBErrorNoticeView errorNoticeInView:self.view title:@"Network Error" message:@"Check your network connection."];
notice.sticky = YES;
[notice show];
}
- (IBAction)showStickyErrorNoticeAndPush:(id)sender
{
WBErrorNoticeView *notice = [WBErrorNoticeView errorNoticeInView:self.view title:@"Network Error" message:@"Check your network connection."];
notice.sticky = YES;
[notice show];
[self.navigationController pushViewController: [[WBViewController alloc] init] animated:YES];
}
@end

View File

@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="1.1" toolsVersion="2182" systemVersion="11E53" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="mRO-Fr-kEU">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2840" systemVersion="12C54" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="mRO-Fr-kEU">
<dependencies>
<deployment defaultVersion="1296" identifier="iOS"/>
<development defaultVersion="4200" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1181"/>
<deployment defaultVersion="1536" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1926"/>
</dependencies>
<scenes>
<!--View Controller - NoticeView-->
<scene sceneID="5">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
<viewController id="2" customClass="WBViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3">
<rect key="frame" x="0.0" y="64" width="320" height="416"/>
@@ -139,6 +137,21 @@
<action selector="showSmallStickyNotice:" destination="2" eventType="touchUpInside" id="F96-6G-a61"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="L3v-hl-Vfi">
<rect key="frame" x="22" y="288" width="130" height="37"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="11"/>
<state key="normal" title="Sticky Error">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showStickyError:" destination="2" eventType="touchUpInside" id="Ezy-Ea-k7g"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="cee-Xq-cSc">
<rect key="frame" x="22" y="244" width="130" height="37"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
@@ -169,6 +182,21 @@
<action selector="showStickyNoticeAndPush:" destination="2" eventType="touchUpInside" id="5zd-aY-Mhi"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="m37-qX-16L">
<rect key="frame" x="170" y="288" width="130" height="37"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="11"/>
<state key="normal" title="Sticky Error Push">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showStickyErrorNoticeAndPush:" destination="2" eventType="touchUpInside" id="86X-rG-EXs"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
@@ -177,13 +205,13 @@
<outlet property="headerView" destination="yEx-cM-vtz" id="Pxy-W0-NzF"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="585" y="218"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="TQy-EY-xtH">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="F0f-Kj-XaR" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController definesPresentationContext="YES" id="mRO-Fr-kEU" sceneMemberID="viewController">
<navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="brG-MW-mKF">
<autoresizingMask key="autoresizingMask"/>
@@ -192,6 +220,7 @@
<segue destination="2" kind="relationship" relationship="rootViewController" id="ojO-yi-Vbu"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="F0f-Kj-XaR" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="137" y="218"/>
</scene>
@@ -208,9 +237,12 @@
<relationship kind="action" name="showSmallErrorNotice:"/>
<relationship kind="action" name="showSmallErrorNoticeAndPush:"/>
<relationship kind="action" name="showSmallErrorNoticeBelow:"/>
<relationship kind="action" name="showSmallStickyNotice:"/>
<relationship kind="action" name="showSmallStickyNoticeBelow:"/>
<relationship kind="action" name="showSmallSuccessNotice:"/>
<relationship kind="action" name="showSmallSuccessNoticeBelow:"/>
<relationship kind="action" name="showStickyError:"/>
<relationship kind="action" name="showStickyErrorNoticeAndPush:"/>
<relationship kind="action" name="showStickyNoticeAndPush:"/>
<relationship kind="outlet" name="headerView" candidateClass="UIImageView"/>
</relationships>