This repository has been archived by the owner on Nov 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIncomingCallView.m
76 lines (59 loc) · 2.21 KB
/
IncomingCallView.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
#import "ImageLabel.h"
#import "UIImage-Private.h"
#import "UIView-Center.h"
#import "IncomingCallView.h"
@implementation IncomingCallView
- (id)initWithDefaultFrameAndBundle:(NSBundle *)resourceBundle {
if ((self = [super initWithFrame:CGRectMake(3, 52, 314, 42)])) {
isLabeled = NO;
pending = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[self addSubview:pending];
caller = [[ImageLabel alloc] initWithFrame:[self bounds] withImage:[UIImage imageNamed:@"callerIcon" inBundle:resourceBundle]];
[self addSubview:caller];
location = [[ImageLabel alloc] initWithFrame:[self bounds] withImage:[UIImage imageNamed:@"locationIcon" inBundle:resourceBundle]];
[self addSubview:location];
[self setNeedsLayout];
}
return self;
}
- (void)dealloc {
[locationFallback release];
[pending release];
[caller release];
[location release];
[super dealloc];
}
- (void)didMoveToSuperview {
if (isLabeled) {
[self fadeInSubview:0];
} else {
[pending startAnimating];
}
}
- (void)layoutSubviews {
for (UIView *subview in [self subviews]) {
[subview centerBothAxes];
}
}
- (void)fadeInSubview:(NSUInteger)index {
UIView *current = [[self subviews] objectAtIndex:index];
[UIView animateWithDuration:1 delay:0.5 options:0 animations:^{ [current setAlpha:1]; } completion:^(BOOL finished){ if (finished) [self fadeOutSubview:index]; }];
}
- (void)fadeOutSubview:(NSUInteger)index {
UIView *current = [[self subviews] objectAtIndex:index];
[UIView animateWithDuration:1 delay:1 options:0 animations:^{ [current setAlpha:0]; } completion:^(BOOL finished){ if (finished) [self fadeInSubview:(index+1)%[[self subviews] count]]; }];
}
- (void)setLocationFallback:(NSString *)aLocation {
[locationFallback release];
locationFallback = [[NSString alloc] initWithString:aLocation];
}
- (void)setCallerAndFinalize:(NSString *)aCaller {
[caller setLabel:aCaller];
[location setLabel:locationFallback];
[pending stopAnimating];
[pending removeFromSuperview];
isLabeled = YES;
[self setNeedsLayout];
[self fadeInSubview:0];
}
@end