@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end
define kRowH 40
define kSectionH 50
@implementation ViewController
-
(void)viewDidLoad {
[super viewDidLoad];
self.title = @"年后";
self.navigationController.navigationBar.translucent = NO;
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Yosemite"]];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;_tableView = [[UITableView alloc] initWithFrame:(CGRect){CGPointZero,{CGRectGetWidth(self.view.frame),CGRectGetHeight(self.view.frame)-64}}];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.rowHeight = kRowH;
_tableView.sectionHeaderHeight = kSectionH;
_tableView.tableFooterView = [UIView new];
_tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iphone6"]];
[self.view addSubview:_tableView];
}
pragma mark - TableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 12;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"12"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"12"];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@-%@",@(indexPath.section),@(indexPath.row)];
return cell;
} - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [NSString stringWithFormat:@"%@-------------",@(section)];
}
pragma mark - ScrollView
-
(void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = kSectionH;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}if (ABS(scrollView.contentOffset.y) < 30) {
if ([scrollView isKindOfClass:[UITableView class]]) {
CGFloat scale = 1-ABS(scrollView.contentOffset.y)/30;
_tableView.backgroundView.transform = CGAffineTransformMakeScale(scale, scale);
}
}
}
(void)scrollViewDidEndDecelerating:(UIScrollView )scrollView {
if (scrollView.contentSize.height < CGRectGetHeight(scrollView.frame)) {
[scrollView setContentOffset:CGPointZero animated:NO];
}
NSLog(@"*********\noffset is %f,\n height is %f\n,**\n ivewH is %f",scrollView.contentOffset.y,scrollView.contentSize.height,scrollView.frame.size.height);
}-
(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
if (scrollView.contentSize.height < CGRectGetHeight(scrollView.frame)) {
[scrollView setContentOffset:CGPointZero animated:YES];
}
}NSLog(@"*********\noffset is %f,\n height is %f\n,***\n ivewH is %f",scrollView.contentOffset.y,scrollView.contentSize.height,scrollView.frame.size.height);
}