Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (66 sloc) 2.188 kB
e1414dd @soffes Added address bar
soffes authored
1 //
2 // SSAddressBarTextFieldBackgroundView.m
3 // SSToolkit
4 //
5 // Created by Sam Soffes on 2/8/11.
e8c3ce3 @soffes Updated comments and renamed SSDrawingMacros to SSDrawingUtilities
soffes authored
6 // Copyright 2011 Sam Soffes. All rights reserved.
e1414dd @soffes Added address bar
soffes authored
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)
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
17
18 - (void)_setupAnimation;
19
e1414dd @soffes Added address bar
soffes authored
20 @end
21
22 @implementation SSAddressBarTextFieldBackgroundView
23
24 @synthesize loading;
25
62be25e @soffes Updated coding style and started on extremitiesStyle
soffes authored
26 - (void)setLoading:(BOOL)isLoading {
27 if (_loading == isLoading) {
28 return;
29 }
30 _loading = isLoading;
31
32 if (_loading) {
33 [self _setupAnimation];
34 [_innerView fadeIn];
35 } else {
36 [_innerView fadeOut];
37 }
38 [self setNeedsDisplay];
39 }
40
41
bf2d0ec @soffes Started overhauling documentation
soffes authored
42 #pragma mark - NSObject
e1414dd @soffes Added address bar
soffes authored
43
44 - (void)dealloc {
45 [_innerView release];
46 [super dealloc];
47 }
48
49
bf2d0ec @soffes Started overhauling documentation
soffes authored
50 #pragma mark - UIView
e1414dd @soffes Added address bar
soffes authored
51
52 - (id)initWithFrame:(CGRect)aFrame {
53 if ((self = [super initWithFrame:aFrame])) {
54 self.layer.cornerRadius = 6.0f;
55
56 self.backgroundColor = [UIColor clearColor];
57 self.alpha = 0.8f;
58 self.opaque = NO;
59 self.clipsToBounds = YES;
60 self.userInteractionEnabled = NO;
61 self.contentMode = UIViewContentModeRedraw;
62
63 _innerView = [[SSAddressBarTextFieldBackgroundViewInnerView alloc] initWithFrame:CGRectZero];
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
64 [self addSubview:_innerView];
e1414dd @soffes Added address bar
soffes authored
65 }
66 return self;
67 }
68
69
bf2d0ec @soffes Started overhauling documentation
soffes authored
70 #pragma mark - Private Methods
e1414dd @soffes Added address bar
soffes authored
71
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
72 - (void)_setupAnimation {
73
74 if (![_innerView.layer animationForKey:@"translation"]) {
75 _innerView.frame = CGRectMake(0, 0, self.frame.size.width + kLoadingBackgroundWidth, self.frame.size.height);
76 CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
77 translation.duration = 3;
78 translation.repeatCount = INFINITY;
79 translation.autoreverses = NO;
80 translation.fromValue = [NSNumber numberWithFloat: - kLoadingBackgroundWidth];
81 translation.toValue = [NSNumber numberWithFloat: 0.0f];
fa18727 Get rid of unused code in address bar animation and add ease-in effect
Andrew Wang authored
82
83 CAMediaTimingFunction *easeInEffect = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
84 [translation setTimingFunction:easeInEffect];
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
85 [_innerView.layer addAnimation:translation forKey:@"translation"];
86 }
87 }
88
e1414dd @soffes Added address bar
soffes authored
89 @end
Something went wrong with that request. Please try again.