代码是通过Tableview来说明的,用在其他情况下同样适用
- (void)viewDidLoad { [super viewDidLoad]; _imageview = [[UIImageView alloc]init]; _imageview.image = [UIImage imageNamed:@"F2.jpg"]; self.imageview.frame =CGRectMake(0, -150, self.tableView.frame.size.width, 150); //此处不能通过添加headerView的方式,因为添加headerview只能设置view的高 [self.tableView addSubview:_imageview]; self.tableView.contentInset = UIEdgeInsetsMake(150, 0, 0, 0); } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 100; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; cell.textLabel.text = @"我是cell"; return cell; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)scrollViewDidScroll:(UIScrollView *)scrollView { //通过滑动的便宜距离重新给图片设置大小 CGFloat yOffset = scrollView.contentOffset.y; if(yOffset<-150) { CGRect f= self.imageview.frame; f.origin.y= yOffset; f.size.height = -yOffset; self.imageview.frame = f; } }