1 #pragma mark 隐藏视图
2 - (void)hideSelfViewWithDelay{
3 [self performSelector:@selector(hideSelfView) withObject:nil afterDelay:2];
4 }
5
6 - (void)cancelHideSelfViewWithDelay{
7 [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideSelfView) object:nil];
8 }
9
10
11 /**
12 更新 toast 提示, 重新延迟2秒显示
13 */
14 - (void)restartHideSelfViewWithDelay{
15 [self cancelHideSelfViewWithDelay];
16 [self hideSelfViewWithDelay];
17 }
18
19
20 - (void)hideSelfView{
21 self.alpha = 1;
22 [UIView animateWithDuration:0.25 animations:^{
23 self.alpha = 0.1;
24 } completion:^(BOOL finished) {
25 self.hidden = YES;
26 }];
27 }
28
29
30 /**
31 如果已经显示, 就不添加动画
32 */
33 - (void)showSelfView{
34 if (self.hidden == YES) {
35 self.hidden = NO;
36 self.alpha = 0.1;
37 [UIView animateWithDuration:0.25 animations:^{
38 self.alpha = 1;
39 }];
40 }
41
42 [self restartHideSelfViewWithDelay];
43 }
44
45 - (void)dealloc{
46 [self cancelHideSelfViewWithDelay];
47 }