forked from Tencent/QMUI_iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQMUIToastAnimator.m
More file actions
72 lines (62 loc) · 1.84 KB
/
Copy pathQMUIToastAnimator.m
File metadata and controls
72 lines (62 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// QMUIToastAnimator.m
// qmui
//
// Created by zhoonchen on 2016/12/12.
// Copyright © 2016年 QMUI Team. All rights reserved.
//
#import "QMUIToastAnimator.h"
#import "QMUICore.h"
#import "QMUIToastView.h"
@implementation QMUIToastAnimator {
BOOL _isShowing;
BOOL _isAnimating;
}
- (instancetype)init {
NSAssert(NO, @"请使用initWithToastView:初始化");
return [self initWithToastView:nil];
}
- (instancetype)initWithCoder:(NSCoder *)coder {
NSAssert(NO, @"请使用initWithToastView:初始化");
return [self initWithToastView:nil];
}
- (instancetype)initWithToastView:(QMUIToastView *)toastView {
NSAssert(toastView, @"toastView不能为空");
if (self = [super init]) {
_toastView = toastView;
}
return self;
}
- (void)showWithCompletion:(void (^)(BOOL finished))completion {
_isShowing = YES;
_isAnimating = YES;
[UIView animateWithDuration:0.25 delay:0.0 options:QMUIViewAnimationOptionsCurveOut|UIViewAnimationOptionBeginFromCurrentState animations:^{
self.toastView.backgroundView.alpha = 1.0;
self.toastView.contentView.alpha = 1.0;
} completion:^(BOOL finished) {
_isAnimating = NO;
if (completion) {
completion(finished);
}
}];
}
- (void)hideWithCompletion:(void (^)(BOOL finished))completion {
_isShowing = NO;
_isAnimating = YES;
[UIView animateWithDuration:0.25 delay:0.0 options:QMUIViewAnimationOptionsCurveOut|UIViewAnimationOptionBeginFromCurrentState animations:^{
self.toastView.backgroundView.alpha = 0.0;
self.toastView.contentView.alpha = 0.0;
} completion:^(BOOL finished) {
_isAnimating = NO;
if (completion) {
completion(finished);
}
}];
}
- (BOOL)isShowing {
return _isShowing;
}
- (BOOL)isAnimating {
return _isAnimating;
}
@end