Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 91 lines (67 sloc) 2.166 kb
e1414dd @soffes Added address bar
soffes authored
1 //
2 // SSAddressBarTextFieldBackgroundView.m
3 // SSToolkit
4 //
5 // Created by Sam Soffes on 2/8/11.
6 // Copyright 2010 Sam Soffes. All rights reserved.
7 //
8
9 #import "SSAddressBarTextFieldBackgroundView.h"
10 #import "SSAddressBarTextFieldBackgroundViewInnerView.h"
11 #import "UIView+SSToolkitAdditions.h"
12 #import <QuartzCore/QuartzCore.h>
13
14 static CGFloat kLoadingBackgroundWidth = 49.0f;
15
16 @interface SSAddressBarTextFieldBackgroundView (PrivateMethods)
17 - (void)_moveStep:(NSTimer *)timer;
18 @end
19
20 @implementation SSAddressBarTextFieldBackgroundView
21
22 @synthesize loading;
23
24 #pragma mark NSObject
25
26 - (void)dealloc {
27 [_moveTimer invalidate];
28 [_moveTimer release];
29 [_innerView release];
30 [super dealloc];
31 }
32
33
34 #pragma mark UIView
35
36 - (id)initWithFrame:(CGRect)aFrame {
37 if ((self = [super initWithFrame:aFrame])) {
38 self.layer.cornerRadius = 6.0f;
39
40 self.backgroundColor = [UIColor clearColor];
41 self.alpha = 0.8f;
42 self.opaque = NO;
43 self.clipsToBounds = YES;
44 self.userInteractionEnabled = NO;
45 self.contentMode = UIViewContentModeRedraw;
46
47 _innerView = [[SSAddressBarTextFieldBackgroundViewInnerView alloc] initWithFrame:CGRectZero];
48 [self addSubview:_innerView];
49
50 _moveTimer = [[NSTimer alloc] initWithFireDate:[NSDate distantFuture] interval:0.08 target:self selector:@selector(_moveStep:) userInfo:nil repeats:YES];
51 [[NSRunLoop mainRunLoop] addTimer:_moveTimer forMode:NSDefaultRunLoopMode];
52 }
53 return self;
54 }
55
56
57 #pragma mark Private Methods
58
59 - (void)_moveStep:(NSTimer *)timer {
60 CGFloat frameX = self.frame.origin.x;
61 CGFloat loadingX = _innerView.frame.origin.x;
62
63 if (loadingX >= frameX) {
64 loadingX = frameX - kLoadingBackgroundWidth - 1.0f;
65 }
66 loadingX = loadingX + 1.0f;
67
68 _innerView.frame = CGRectMake(loadingX, self.frame.origin.y, self.frame.size.width + kLoadingBackgroundWidth, self.frame.size.height);
69 }
70
71
72 #pragma mark Setters
73
74 - (void)setLoading:(BOOL)isLoading {
75 if (_loading == isLoading) {
76 return;
77 }
78 _loading = isLoading;
79
80 if (_loading) {
81 [_moveTimer setFireDate:[NSDate date]];
82 [_innerView fadeIn];
83 } else {
84 [_moveTimer setFireDate:[NSDate distantFuture]];
85 [_innerView fadeOut];
86 }
87 [self setNeedsDisplay];
88 }
89
90 @end
Something went wrong with that request. Please try again.