-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathUIDickBarController.m
152 lines (102 loc) · 3.07 KB
/
UIDickBarController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// UIDickBarController.m
// UIDickBar
//
// Created by Daniel Tull on 08.03.2011.
// Copyright 2011 Daniel Tull. All rights reserved.
//
#import "UIDickBarController.h"
@implementation UIDickBarController
@synthesize tableView, dickBar;
- (void)dealloc {
[tableView release], tableView = nil;
[dickBar release], dickBar = nil;
[super dealloc];
}
#pragma mark - UIDickBarController
- (void)loadTableView {}
- (UITableView *)tableView {
if (!(tableView)) [self loadTableView];
if (!(tableView)) {
tableView = [[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStylePlain];
}
return [[tableView retain] autorelease];
}
- (void)loadDickBar {}
- (UIDickBar *)dickBar {
if (!(dickBar)) [self loadDickBar];
if (!(dickBar)) {
dickBar = [[UIDickBar alloc] initWithDickTitle:@"Dick Bar"
dickBadge:@"Badge"
actionBlock:nil];
}
return [[dickBar retain] autorelease];
}
- (IBAction)toggleDickBar:(id)sender {
if (dickBarShowing)
[self hideDickBar];
else
[self showDickBar];
}
- (void)hideDickBar {
UIView *v = self.tableView.tableHeaderView;
if ([self.dickBar.superview isEqual:v]) {
NSArray *subviews = [v.subviews retain];
for (UIView *s in subviews)
[s removeFromSuperview];
v.frame = CGRectMake(v.frame.origin.x, v.frame.origin.y, v.frame.size.width, v.frame.size.height - 44.0f);
for (UIView *s in subviews) {
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y - 44.0f, s.frame.size.width, s.frame.size.height);
[v addSubview:s];
}
[subviews release];
self.tableView.tableHeaderView = v;
} else {
[self.dickBar removeFromSuperview];
}
dickBarShowing = NO;
}
- (void)showDickBar {
if (self.tableView.contentOffset.y > self.dickBar.bounds.size.height)
[self.dickBar showInView:self.view];
else {
UIView *v = self.tableView.tableHeaderView;
if (!(v)) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 0.0f)];
self.tableView.tableHeaderView = view;
[view release];
}
v = self.tableView.tableHeaderView;
NSArray *subviews = [v.subviews retain];
for (UIView *s in subviews)
[s removeFromSuperview];
v.frame = CGRectMake(v.frame.origin.x, v.frame.origin.y, v.frame.size.width, v.frame.size.height + 44.0f);
for (UIView *s in subviews) {
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y + 44.0f, s.frame.size.width, s.frame.size.height);
[v addSubview:s];
}
[subviews release];
[self.dickBar showInView:v];
self.tableView.tableHeaderView = v;
}
dickBarShowing = YES;
}
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self showDickBar];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.tableView = nil;
self.dickBar = nil;
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
@end