#import "MyViewController.h"
CGFloat const imageW=320;
CGFloat const imageH=320;
CGFloat const inseTop=150;
@interface MyViewController ()
@property (nonatomic ,strong)UIImageView *myimageView;
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.contentInset=UIEdgeInsetsMake(inseTop, 0, 0, 0);
self.myimageView=[[UIImageView alloc]init];
self.myimageView.image=[UIImage imageNamed:@"1436262350712853.jpg"];
self.myimageView.frame=CGRectMake(0, -inseTop, imageW, imageH);
//设置内容模式,也是核心代码
self.myimageView.contentMode=UIViewContentModeScaleAspectFill;
[self.tableView insertSubview:self.myimageView atIndex:0];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - 核心代码
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat dragdelta=-inseTop-scrollView.contentOffset.y;
if (dragdelta<0)
{
dragdelta=0;
}
CGRect new=self.myimageView.frame;
new.size.height=inseTop+dragdelta;
self.myimageView.frame=new;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID=@"id";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
NSString *title=[NSString stringWithFormat:@"哈哈:%ld",indexPath.row];
cell.textLabel.text=title;
return cell;
}
@end
CGFloat const imageW=320;
CGFloat const imageH=320;
CGFloat const inseTop=150;
@interface MyViewController ()
@property (nonatomic ,strong)UIImageView *myimageView;
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.contentInset=UIEdgeInsetsMake(inseTop, 0, 0, 0);
self.myimageView=[[UIImageView alloc]init];
self.myimageView.image=[UIImage imageNamed:@"1436262350712853.jpg"];
self.myimageView.frame=CGRectMake(0, -inseTop, imageW, imageH);
//设置内容模式,也是核心代码
self.myimageView.contentMode=UIViewContentModeScaleAspectFill;
[self.tableView insertSubview:self.myimageView atIndex:0];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - 核心代码
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat dragdelta=-inseTop-scrollView.contentOffset.y;
if (dragdelta<0)
{
dragdelta=0;
}
CGRect new=self.myimageView.frame;
new.size.height=inseTop+dragdelta;
self.myimageView.frame=new;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID=@"id";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
NSString *title=[NSString stringWithFormat:@"哈哈:%ld",indexPath.row];
cell.textLabel.text=title;
return cell;
}
@end