Permalink
Browse files

Make a toggle action to show and hide the dick bar in its annoying way

  • Loading branch information...
1 parent 8b32511 commit acb648df9603a59b1051fbac66d0022dc04b1d5f @danielctull danielctull committed Mar 8, 2011
Showing with 86 additions and 2 deletions.
  1. +5 −1 UIDickBarController.h
  2. +81 −1 UIDickBarController.m
View
@@ -10,7 +10,7 @@
#import "UIDickBar.h"
@interface UIDickBarController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
- BOOL dickBarScrolledOffScreen;
+ BOOL dickBarShowing;
}
@property (nonatomic, retain) IBOutlet UIDickBar *dickBar;
@@ -19,4 +19,8 @@
- (void)loadTableView;
- (void)loadDickBar;
+- (IBAction)toggleDickBar:(id)sender;
+- (void)hideDickBar;
+- (void)showDickBar;
+
@end
View
@@ -50,11 +50,91 @@ - (UIDickBar *)dickBar {
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 showInView:nil];
+ }
+
+ 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.dickBar showInView:self.view];
+ [self showDickBar];
+
+ UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"toggle" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleDickBar:)];
+ self.navigationItem.rightBarButtonItem = item;
+ [item release];
}
- (void)viewDidUnload {

0 comments on commit acb648d

Please sign in to comment.