Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions KSToastView/KSToastView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 24 additions & 1 deletion KSToastView/KSToastView.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
static CGFloat _offsetTop = KS_TOAST_VIEW_OFFSET_TOP;
static UIEdgeInsets _textInsets;
static NSTextAlignment _textAligment = NSTextAlignmentCenter;
UIView *toastView;

@interface KSToastView ()

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down