#import "ViewController.h"
#define W [UIScreen mainScreen].bounds.size.width
#define H [UIScreen mainScreen].bounds.size.height
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (
nonatomic, retain)
UITableView *tableView;
@property (
nonatomic, retain)
NSMutableArray *arraySource;
@end
@implementation ViewController
- (
void)viewDidLoad {
[
super viewDidLoad];
self.arraySource = [[
NSMutableArray alloc]init];
self.tableView = [[
UITableView alloc]initWithFrame:CGRectMake(
0,
20, W, H-
20) style:UITableViewStylePlain];
self.tableView.delegate =
self;
self.tableView.dataSource =
self;
[
self.view addSubview:
self.tableView];
for (
NSInteger i =
0; i <
10; i++) {
NSString *str = [
NSString stringWithFormat:@
"====我是第%ld行====", i];
[
self.arraySource addObject:str];
}
self.tableView.contentInset = UIEdgeInsetsMake(
200,
0,
0,
0);
UIImageView *imageView = [[
UIImageView alloc] initWithFrame:CGRectMake(
0, -
200, [UIScreen mainScreen]
.bounds.size.width,
200)];
imageView
.image = [
UIImage imageNamed:@
"1"];
imageView
.contentMode = UIViewContentModeScaleAspectFill;
imageView
.tag =
101;
[
self.tableView addSubview:imageView];
}
#pragma make - UITableViewDataSource
-(
NSInteger)numberOfSectionsInTableView:(
UITableView *)tableView
{
return 1;
}
-(
NSInteger)tableView:(
UITableView *)tableView numberOfRowsInSection:(
NSInteger)section
{
return self.arraySource.count;
}
-(
UITableViewCell *)tableView:(
UITableView *)tableView cellForRowAtIndexPath:(
NSIndexPath *)indexPath
{
static NSString *cellID = @
"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell ==
nil) {
cell = [[
UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
cell
.textLabel.text =
self.arraySource[indexPath
.row];
}
return cell;
}
- (
CGFloat)tableView:(
UITableView *)tableView heightForRowAtIndexPath:(
NSIndexPath *)indexPath
{
return 100;
}
-(
void)tableView:(
UITableView *)tableView didSelectRowAtIndexPath:(
NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:
YES];
}
- (
void)scrollViewDidScroll:(
UIScrollView *)scrollView
{
CGPoint point = scrollView
.contentOffset;
if (point
.y < -
200) {
CGRect rect = [
self.tableView viewWithTag:
101]
.frame;
rect
.origin.y = point
.y;
rect
.size.height = -point
.y;
[
self.tableView viewWithTag:
101]
.frame = rect;
}
}
- (
void)didReceiveMemoryWarning {
[
super didReceiveMemoryWarning];
}
@end