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.203 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
26 #pragma mark NSObject
27
28 - (void)dealloc {
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];
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
48 [self addSubview:_innerView];
e1414dd @soffes Added address bar
soffes authored
49 }
50 return self;
51 }
52
53
54 #pragma mark Private Methods
55
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
56 - (void)_setupAnimation {
57
58 if (![_innerView.layer animationForKey:@"translation"]) {
59 _innerView.frame = CGRectMake(0, 0, self.frame.size.width + kLoadingBackgroundWidth, self.frame.size.height);
60 CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
61 translation.duration = 3;
62 translation.repeatCount = INFINITY;
63 translation.autoreverses = NO;
64 translation.fromValue = [NSNumber numberWithFloat: - kLoadingBackgroundWidth];
65 translation.toValue = [NSNumber numberWithFloat: 0.0f];
fa18727 Get rid of unused code in address bar animation and add ease-in effect
Andrew Wang authored
66
67 CAMediaTimingFunction *easeInEffect = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
68 [translation setTimingFunction:easeInEffect];
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
69 [_innerView.layer addAnimation:translation forKey:@"translation"];
70 }
71 }
72
e1414dd @soffes Added address bar
soffes authored
73 #pragma mark Setters
74
75 - (void)setLoading:(BOOL)isLoading {
76 if (_loading == isLoading) {
77 return;
78 }
79 _loading = isLoading;
80
81 if (_loading) {
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
82 [self _setupAnimation];
e1414dd @soffes Added address bar
soffes authored
83 [_innerView fadeIn];
84 } else {
85 [_innerView fadeOut];
86 }
87 [self setNeedsDisplay];
88 }
89
90 @end
Something went wrong with that request. Please try again.