forked from soffes/sstoolkit
-
Notifications
You must be signed in to change notification settings - Fork 100
/
SSAddressBarTextFieldBackgroundView.m
92 lines (68 loc) · 2.21 KB
/
SSAddressBarTextFieldBackgroundView.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
84
85
86
87
88
89
90
91
92
//
// SSAddressBarTextFieldBackgroundView.m
// SSToolkit
//
// Created by Sam Soffes on 2/8/11.
// Copyright 2011 Sam Soffes. All rights reserved.
//
#import "SSAddressBarTextFieldBackgroundView.h"
#import "SSAddressBarTextFieldBackgroundViewInnerView.h"
#import "UIView+SSToolkitAdditions.h"
#import <QuartzCore/QuartzCore.h>
static CGFloat kLoadingBackgroundWidth = 49.0f;
@interface SSAddressBarTextFieldBackgroundView (PrivateMethods)
- (void)_setupAnimation;
@end
@implementation SSAddressBarTextFieldBackgroundView {
SSAddressBarTextFieldBackgroundViewInnerView *_innerView;
}
@synthesize loading = _loading;
- (void)setLoading:(BOOL)isLoading {
if (_loading == isLoading) {
return;
}
_loading = isLoading;
if (_loading) {
[self _setupAnimation];
[_innerView fadeIn];
} else {
[_innerView fadeOut];
}
[self setNeedsDisplay];
}
#pragma mark - NSObject
- (void)dealloc {
[_innerView release];
[super dealloc];
}
#pragma mark - UIView
- (id)initWithFrame:(CGRect)aFrame {
if ((self = [super initWithFrame:aFrame])) {
self.layer.cornerRadius = 6.0f;
self.backgroundColor = [UIColor clearColor];
self.alpha = 0.8f;
self.opaque = NO;
self.clipsToBounds = YES;
self.userInteractionEnabled = NO;
self.contentMode = UIViewContentModeRedraw;
_innerView = [[SSAddressBarTextFieldBackgroundViewInnerView alloc] initWithFrame:CGRectZero];
[self addSubview:_innerView];
}
return self;
}
#pragma mark - Private Methods
- (void)_setupAnimation {
if (![_innerView.layer animationForKey:@"translation"]) {
_innerView.frame = CGRectMake(0, 0, self.frame.size.width + kLoadingBackgroundWidth, self.frame.size.height);
CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
translation.duration = 3;
translation.repeatCount = INFINITY;
translation.autoreverses = NO;
translation.fromValue = [NSNumber numberWithFloat: - kLoadingBackgroundWidth];
translation.toValue = [NSNumber numberWithFloat: 0.0f];
CAMediaTimingFunction *easeInEffect = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[translation setTimingFunction:easeInEffect];
[_innerView.layer addAnimation:translation forKey:@"translation"];
}
}
@end