From f9e70fdefc1aff8b8285b19dc8fd2a8816cede4d Mon Sep 17 00:00:00 2001 From: Xuanzhong Wei Date: Thu, 20 Feb 2014 20:08:40 +0900 Subject: [PATCH] Add parameter forceDismiss to dismissActiveNotification method in order to dismiss the message even if it is not fully displayed --- TSMessages/Classes/TSMessage.h | 8 ++++++++ TSMessages/Classes/TSMessage.m | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/TSMessages/Classes/TSMessage.h b/TSMessages/Classes/TSMessage.h index 4156f5d0..69c8281b 100755 --- a/TSMessages/Classes/TSMessage.h +++ b/TSMessages/Classes/TSMessage.h @@ -115,6 +115,14 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) { */ + (BOOL)dismissActiveNotification; +/** Fades out the currently displayed notification. If another notification is in the queue, + the next one will be displayed automatically + @param forceDismiss Should the message be dismissed even if it is not fully displayed + @return YES if the currently displayed notification was successfully dismissed. NO if no notification + was currently displayed. + */ ++ (BOOL)dismissActiveNotification:(BOOL)forceDismiss; + /** Use this method to set a default view controller to display the messages in */ + (void)setDefaultViewController:(UIViewController *)defaultViewController; diff --git a/TSMessages/Classes/TSMessage.m b/TSMessages/Classes/TSMessage.m index 5fbb149e..5eee07b6 100755 --- a/TSMessages/Classes/TSMessage.m +++ b/TSMessages/Classes/TSMessage.m @@ -306,7 +306,7 @@ - (void)fadeOutNotification:(TSMessageView *)currentView }]; } -+ (BOOL)dismissActiveNotification ++ (BOOL)dismissActiveNotification:(BOOL)forceDismiss { if ([[TSMessage sharedMessage].messages count] == 0) return NO; @@ -314,7 +314,7 @@ + (BOOL)dismissActiveNotification { if ([[TSMessage sharedMessage].messages count] == 0) return; TSMessageView *currentMessage = [[TSMessage sharedMessage].messages objectAtIndex:0]; - if (currentMessage.messageIsFullyDisplayed) + if (forceDismiss || currentMessage.messageIsFullyDisplayed) { [[TSMessage sharedMessage] fadeOutNotification:currentMessage]; } @@ -322,6 +322,11 @@ + (BOOL)dismissActiveNotification return YES; } ++ (BOOL)dismissActiveNotification +{ + return [TSMessage dismissActiveNotification: NO]; +} + #pragma mark Customizing TSMessages + (void)setDefaultViewController:(UIViewController *)defaultViewController