wxr
2020-06-16 f6fd8acd7c53c44187e70b4709443318a628f4b5
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
//  AMPopTip+Entrance.m
//  AMPopTip
//
//  Created by Andrea Mazzini on 10/06/15.
//  Copyright (c) 2015 Fancy Pixel. All rights reserved.
//
 
#import "AMPopTip+Entrance.h"
 
@implementation AMPopTip (Entrance)
 
- (void)performEntranceAnimation:(void (^)())completion {
    switch (self.entranceAnimation) {
        case AMPopTipEntranceAnimationScale: {
            [self entranceScale:completion];
            break;
        }
        case AMPopTipEntranceAnimationTransition: {
            [self entranceTransition:completion];
            break;
        }
        case AMPopTipEntranceAnimationCustom: {
            [self.containerView addSubview:self];
            if (self.entranceAnimationHandler) {
                self.entranceAnimationHandler(^{
                    completion();
                });
            }
        }
        case AMPopTipEntranceAnimationNone: {
            [self.containerView addSubview:self];
            completion();
            break;
        }
        default: {
            [self.containerView addSubview:self];
            completion();
            break;
        }
    }
}
 
- (void)entranceTransition:(void (^)())completion {
    self.transform = CGAffineTransformMakeScale(0.6, 0.6);
    switch (self.direction) {
        case AMPopTipDirectionUp:
            self.transform = CGAffineTransformTranslate(self.transform, 0, -self.fromFrame.origin.y);
            break;
        case AMPopTipDirectionDown:
            self.transform = CGAffineTransformTranslate(self.transform, 0, (self.containerView.frame.size.height - self.fromFrame.origin.y));
            break;
        case AMPopTipDirectionLeft:
            self.transform = CGAffineTransformTranslate(self.transform, -self.fromFrame.origin.x, 0);
            break;
        case AMPopTipDirectionRight:
            self.transform = CGAffineTransformTranslate(self.transform, (self.containerView.frame.size.width - self.fromFrame.origin.x), 0);
            break;
        case AMPopTipDirectionNone:
            self.transform = CGAffineTransformTranslate(self.transform, 0, (self.containerView.frame.size.height - self.fromFrame.origin.y));
            break;
 
        default:
            break;
    }
    [self.containerView addSubview:self];
 
    [UIView animateWithDuration:self.animationIn delay:self.delayIn usingSpringWithDamping:0.6 initialSpringVelocity:1.5 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState) animations:^{
        self.transform = CGAffineTransformIdentity;
    } completion:^(BOOL completed){
        if (completed) {
            completion();
        }
    }];
}
 
- (void)entranceScale:(void (^)())completion {
    self.transform = CGAffineTransformMakeScale(0, 0);
    [self.containerView addSubview:self];
 
    [UIView animateWithDuration:self.animationIn delay:self.delayIn usingSpringWithDamping:0.6 initialSpringVelocity:1.5 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState) animations:^{
        self.transform = CGAffineTransformIdentity;
    } completion:^(BOOL completed){
        if (completed) {
            completion();
        }
    }];
}
 
@end