//头部拉伸效果
#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic) UITableView *tabelView;
@property (nonatomic, copy) NSArray *dataSource;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self createUI];
}
-(void)createUI{
self.dataSource = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"1",@"2",@"3",@"4",@"5",@"6",@"7"];
self.tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
self.tabelView.delegate = self;
self.tabelView.dataSource = self;
self.tabelView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
[self.view addSubview:self.tabelView];
UIImageView *headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -200, self.view.frame.size.width, 200)];
headerImageView.image = [UIImage imageNamed:@"mineHeaderBackImage"];
headerImageView.tag = 101;
// headerImageView.contentMode = UIViewContentModeScaleToFill;//上下填充
headerImageView.contentMode = UIViewContentModeScaleAspectFill;//上下左右等比例填充
[self.tabelView addSubview:headerImageView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"string"];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"string"];
}
cell.textLabel.text = self.dataSource[indexPath.row];
return cell;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGRect rect = [self.view viewWithTag:101].frame;
CGPoint point = scrollView.contentOffset;
if (point.y < -200) {
//处于拉伸状态
rect.origin.y = point.y;
rect.size.height = -point.y;
[self.view viewWithTag:101].frame = rect;
}
NSLog(@"point.y %f",point.y);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end