Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 85 lines (63 sloc) 2.175 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 - UIView
e1414dd @soffes Added address bar
soffes authored
46
47 - (id)initWithFrame:(CGRect)aFrame {
48 if ((self = [super initWithFrame:aFrame])) {
49 self.layer.cornerRadius = 6.0f;
50
51 self.backgroundColor = [UIColor clearColor];
52 self.alpha = 0.8f;
53 self.opaque = NO;
54 self.clipsToBounds = YES;
55 self.userInteractionEnabled = NO;
56 self.contentMode = UIViewContentModeRedraw;
57
58 _innerView = [[SSAddressBarTextFieldBackgroundViewInnerView alloc] initWithFrame:CGRectZero];
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
59 [self addSubview:_innerView];
e1414dd @soffes Added address bar
soffes authored
60 }
61 return self;
62 }
63
64
bf2d0ec @soffes Started overhauling documentation
soffes authored
65 #pragma mark - Private Methods
e1414dd @soffes Added address bar
soffes authored
66
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
67 - (void)_setupAnimation {
68
69 if (![_innerView.layer animationForKey:@"translation"]) {
70 _innerView.frame = CGRectMake(0, 0, self.frame.size.width + kLoadingBackgroundWidth, self.frame.size.height);
71 CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
72 translation.duration = 3;
73 translation.repeatCount = INFINITY;
74 translation.autoreverses = NO;
75 translation.fromValue = [NSNumber numberWithFloat: - kLoadingBackgroundWidth];
76 translation.toValue = [NSNumber numberWithFloat: 0.0f];
fa18727 Get rid of unused code in address bar animation and add ease-in effect
Andrew Wang authored
77
78 CAMediaTimingFunction *easeInEffect = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
79 [translation setTimingFunction:easeInEffect];
fccf69b Run animation in SSAddressBarTextField on a the non-main thread
Andrew Wang authored
80 [_innerView.layer addAnimation:translation forKey:@"translation"];
81 }
82 }
83
e1414dd @soffes Added address bar
soffes authored
84 @end
Something went wrong with that request. Please try again.