@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableView
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad]
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever
self.navigationController.navigationBar.translucent = NO
[self.view addSubview:self.tableView]
}
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone
_tableView.delegate = self
_tableView.dataSource = self
_tableView.estimatedRowHeight = 0.0
_tableView.sectionHeaderHeight = 0.0
_tableView.sectionFooterHeight = 0.0
_tableView.estimatedSectionHeaderHeight = 0.0
_tableView.estimatedSectionFooterHeight = 0.0
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever
[_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([TittleCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NSStringFromClass([TittleCell class])]
[_tableView registerClass:[ShowCell class] forCellReuseIdentifier:NSStringFromClass([ShowCell class])]
}
return _tableView
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 11
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return cellHeight
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//第6个Cell显示为图片
if (indexPath.row != 5) {
TittleCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([TittleCell class]) forIndexPath:indexPath]
return cell
} else {
ShowCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ShowCell class]) forIndexPath:indexPath]
return cell
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//开始显示图片时的偏移量
CGFloat contentPointY = 5 * cellHeight - kHeight
CGFloat contentOffSet = scrollView.contentOffset.y
NSLog(@"垂直方向偏移量:%f,临界Y值:%f",scrollView.contentOffset.y,contentPointY)
if (contentOffSet >= contentPointY && contentOffSet <= 5 * cellHeight) {
NSIndexPath *indexs = [NSIndexPath indexPathForRow:5 inSection:0]
ShowCell *showcell = [self.tableView cellForRowAtIndexPath:indexs]
showcell.contendOffset = contentOffSet - contentPointY
}
}
@end
