iOS下拉放大的效果
一,code
// 创建UIImageView
UIImageView* topView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IMG_1483"]];
topView.frame = CGRectMake(0, -HGTopViewH, self.tableView.frame.size.width, HGTopViewH);
// 设置模式,自动伸缩,全拼显示
topView.contentMode = UIViewContentModeScaleAspectFill;
// 支持旋转
topView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// 将UIImageView加到TableView中
[self.tableView insertSubview:topView atIndex:0];
// 内嵌
self.tableView.contentInset = UIEdgeInsetsMake(HGTopViewH*0.5, 0, 0, 0);
self.topView = topView;
二,code
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// 向下移动的距离
CGFloat down = -(HGTopViewH*0.5)-scrollView.contentOffset.y;
if (down<0) {
return;
}
// 从新设置frame
CGRect frame = self.topView.frame;
frame.size.height = HGTopViewH + down*2;
self.topView.frame = frame;
}