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