Created
March 25, 2015 13:18
-
-
Save dehydr8/5f85488d776a99c90223 to your computer and use it in GitHub Desktop.
TableView - Stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// ReappearingNavigationBarSample | |
// | |
// Created by Osama Khalid on 25/03/2015. | |
// Copyright (c) 2015 Folio3. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface ViewController () <UITableViewDataSource, UITableViewDelegate> { | |
BOOL hidden; | |
} | |
@property (weak, nonatomic) IBOutlet UITableView *tableView; | |
@end | |
@implementation ViewController | |
@synthesize tableView = _tableView; | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; | |
self.navigationController.navigationBar.shadowImage = [UIImage new]; | |
self.navigationController.navigationBar.translucent = YES; | |
self.tableView.contentInset = UIEdgeInsetsMake(-64,0,0,0); | |
hidden = YES; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
#pragma mark - Table View | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return 30; | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
if (indexPath.row == 0) | |
return 200; | |
return 44; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
UITableViewCell * cell = nil; | |
if (indexPath.row == 0) { | |
cell = [tableView dequeueReusableCellWithIdentifier:@"PictureCell"]; | |
} else { | |
cell = [tableView dequeueReusableCellWithIdentifier:@"ExampleCell"]; | |
cell.textLabel.text = @"Hello"; | |
cell.detailTextLabel.text = @"Some detail"; | |
} | |
return cell; | |
} | |
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { | |
if (scrollView.contentOffset.y > 150) { | |
if (hidden) { | |
NSLog(@"Y: %.1f", scrollView.contentOffset.y); | |
hidden = NO; | |
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; | |
self.navigationController.navigationBar.shadowImage = nil; | |
self.navigationController.navigationBar.translucent = NO; | |
} | |
} else { | |
if (!hidden) { | |
NSLog(@"Y: %.1f", scrollView.contentOffset.y); | |
hidden = YES; | |
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; | |
self.navigationController.navigationBar.shadowImage = [UIImage new]; | |
self.navigationController.navigationBar.translucent = YES; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment