IOS slides tableView to change the color of the navigation bar
-(Void) viewDidLoad {
[Super viewDidLoad];
[Self initTableView];
}
-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {
Return 1;
}
-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {
Return 10;
}
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
UITableViewCell * cell = [self tableViewZ: self. myTableView cellForRowAtIndexPath: indexPath];
Return cell;
}
-(UITableViewCell *) tableViewZ :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
UITableViewCell * cell = [[UITableViewCell alloc] init];
Return cell;
}
-(Void) scrollViewDidScroll :( UIScrollView *) scrollView {
NSLog (@ "offset --- scroll: % f", self. myTableView. contentOffset. y );
UIColor * color = [UIColor redColor];
CGFloat offset = scrollView. contentOffset. y;
If (offset <0 ){
Self. navigationController. navigationBar. backgroundColor = [color colorWithAlphaComponent: 0];
} Else {
CGFloat alpha = 1-(64-offset)/64 );
Self. navigationController. navigationBar. backgroundColor = [color colorWithAlphaComponent: alpha];
}
}
-(Void) initTableView {
Self. myTableView. delegate = self;
Self. myTableView. dataSource = self;
}