From 70d331fc20085fd827f950a64a1af68dbff46233 Mon Sep 17 00:00:00 2001 From: Mokhlas Hussein Date: Sat, 25 Jun 2016 22:53:24 +0200 Subject: [PATCH 1/2] add dismiss methods --- KSToastView/KSToastView.m | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/KSToastView/KSToastView.m b/KSToastView/KSToastView.m index f6450c9..9bd611c 100644 --- a/KSToastView/KSToastView.m +++ b/KSToastView/KSToastView.m @@ -46,6 +46,7 @@ static CGFloat _offsetTop = KS_TOAST_VIEW_OFFSET_TOP; static UIEdgeInsets _textInsets; static NSTextAlignment _textAligment = NSTextAlignmentCenter; +UIView *toastView; @interface KSToastView () @@ -139,7 +140,7 @@ + (void)ks_showToast:(id)toast duration:(NSTimeInterval)duration delay:(NSTimeIn [[keyWindow viewWithTag:KS_TOAST_VIEW_TAG] removeFromSuperview]; [keyWindow endEditing:YES]; - UIView *toastView = [UIView new]; + toastView = [UIView new]; toastView.translatesAutoresizingMaskIntoConstraints = NO; toastView.userInteractionEnabled = NO; toastView.backgroundColor = [self _backgroundColor]; @@ -250,6 +251,28 @@ + (void)ks_setAppearanceMaxHeight:(CGFloat)maxHeight { #pragma mark - Private Methods ++ (void)dismissToastView { + [UIView animateWithDuration:KS_TOAST_VIEW_ANIMATION_DURATION animations: ^{ + toastView.alpha = 0.0f; + } completion: ^(BOOL finished) { + [toastView removeFromSuperview]; + }]; +} + ++ (void)dismissToastViewWithCompletion:(KSToastBlock)completion { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [UIView animateWithDuration:KS_TOAST_VIEW_ANIMATION_DURATION animations: ^{ + toastView.alpha = 0.0f; + } completion: ^(BOOL finished) { + [toastView removeFromSuperview]; + + KSToastBlock block = [completion copy]; + if (block) { + block(); + } + }]; + }); +} + (UIFont *)_textFont { if (_textFont == nil) { _textFont = [UIFont systemFontOfSize:KS_TOAST_VIEW_TEXT_FONT_SIZE]; From bf709d46ff43bff67c55277c460c0aea98227607 Mon Sep 17 00:00:00 2001 From: Mokhlas Hussein Date: Sat, 25 Jun 2016 22:54:09 +0200 Subject: [PATCH 2/2] add dismiss methods to header file --- KSToastView/KSToastView.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/KSToastView/KSToastView.h b/KSToastView/KSToastView.h index 9f01331..7aee3b6 100644 --- a/KSToastView/KSToastView.h +++ b/KSToastView/KSToastView.h @@ -55,6 +55,12 @@ typedef void (^KSToastBlock)(void); + (void)ks_showToast:(id)toast delay:(NSTimeInterval)delay completion:(KSToastBlock)completion; + (void)ks_showToast:(id)toast duration:(NSTimeInterval)duration delay:(NSTimeInterval)delay completion:(KSToastBlock)completion; +/** + * ToastView Dismiss + */ ++ (void)dismissToastView; ++ (void)dismissToastViewWithCompletion:(KSToastBlock)completion; + /** * @Deprecated * Please use + (void)ks_setAppearanceTextInsets:(UIEdgeInsets)textInsets;