-
Notifications
You must be signed in to change notification settings - Fork 330
/
JGProgressHUDFadeZoomAnimation.m
executable file
·83 lines (64 loc) · 3.25 KB
/
JGProgressHUDFadeZoomAnimation.m
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
//
// JGProgressHUDFadeZoomAnimation.m
// JGProgressHUD
//
// Created by Jonas Gessner on 20.7.14.
// Copyright (c) 2014 Jonas Gessner. All rights reserved.
//
#import "JGProgressHUDFadeZoomAnimation.h"
@implementation JGProgressHUDFadeZoomAnimation
#pragma mark - Initializers
- (instancetype)init {
self = [super init];
if (self) {
self.shrinkAnimationDuaration = 0.2;
self.expandAnimationDuaration = 0.1;
self.expandScale = CGSizeMake(1.1f, 1.1f);
}
return self;
}
#pragma mark - Showing
- (void)show {
[super show];
//Prepare the HUD
self.progressHUD.alpha = 0.0f;
self.progressHUD.HUDView.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
NSTimeInterval totalDuration = self.expandAnimationDuaration+self.shrinkAnimationDuaration;
//Show the HUD
self.progressHUD.hidden = NO;
//Now animate the presentation
[UIView animateWithDuration:totalDuration delay:0.0 options:(UIViewAnimationOptions)(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut) animations:^{
self.progressHUD.alpha = 1.0f;
} completion:nil];
[UIView animateWithDuration:self.shrinkAnimationDuaration delay:0.0 options:(UIViewAnimationOptions)(UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState) animations:^{
self.progressHUD.HUDView.transform = CGAffineTransformMakeScale(self.expandScale.width, self.expandScale.height);
} completion:^(BOOL __unused _finished) {
[UIView animateWithDuration:self.expandAnimationDuaration delay:0.0 options:(UIViewAnimationOptions)(UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState) animations:^{
self.progressHUD.HUDView.transform = CGAffineTransformIdentity;
} completion:^(BOOL __unused __finished) {
[self animationFinished];
}];
}];
}
#pragma mark - Hiding
- (void)hide {
[super hide];
NSTimeInterval totalDuration = self.expandAnimationDuaration+self.shrinkAnimationDuaration;
//Animate the dismissal
[UIView animateWithDuration:totalDuration delay:0.0 options:(UIViewAnimationOptions)(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut) animations:^{
self.progressHUD.alpha = 0.0f;
} completion:nil];
[UIView animateWithDuration:self.expandAnimationDuaration delay:0.0 options:(UIViewAnimationOptions)(UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState) animations:^{
self.progressHUD.HUDView.transform = CGAffineTransformMakeScale(self.expandScale.width, self.expandScale.height);
} completion:^(BOOL __unused _finished) {
[UIView animateWithDuration:self.shrinkAnimationDuaration delay:0.0 options:(UIViewAnimationOptions)(UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState) animations:^{
self.progressHUD.HUDView.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
} completion:^(BOOL __unused __finished) {
//HUD is now hidden, restore the transform
self.progressHUD.HUDView.transform = CGAffineTransformIdentity;
//Alway call this last
[self animationFinished];
}];
}];
}
@end