- (void)viewDidLoad {
[super viewDidLoad];
_tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
//創(chuàng)建頭視圖
UIImageView * imageView = [UIImageView new];
_tableView.contentInset = UIEdgeInsetsMake(imageViewH * 0.5, 0, 0, 0);
imageView.frame = CGRectMake(0, -imageViewH, ScreenWidth, imageViewH);
imageView.image = [UIImage imageNamed:@"xifuer.jpeg"];
imageView.contentMode = UIViewContentModeScaleToFill;
[_tableView insertSubview:imageView atIndex:0];
self.imageView = imageView;
[self.view addSubview:_tableView];
}
#pragma mark - 解決tableview分割線短一截問題
- (void)viewDidLayoutSubviews{
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
if ([cell respondsToSelector:@selector(setSeparatorInset:)])
{
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)])
{
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
#pragma mark - tableView代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"123"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"123"];
cell.textLabel.text = @"123";
}
return cell;
}
#pragma mark - 借助scrollview的代理方法實(shí)現(xiàn)視圖收縮放大
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat down = -(imageViewH*0.5) - scrollView.contentOffset.y;
if (down < 0) return;
CGRect frame = _imageView.frame;
frame.size.height = imageViewH + down * 0.5;
frame.size.width = ScreenWidth + down * 0.5;
_imageView.frame = frame;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者