我已经使用表格视图实现了滚动效果,该表格视图的标题 aUIView
为 100 px 高度,背景颜色清晰。在viewDidLoad
我创建一个UIImageView
与表格视图的标题视图(100 px)高度相同的情况下,然后创建一个 UIView,我们将用作表格视图的 backgroundView 并在其顶部添加 UIImageView。在委托方法中,根据滚动视图值scrollViewDidScroll
缩放框架。UIImageView
contentOffset.y
static CGRect headerImgFrame = {{.0, .0}, {320.0, 100.0}};
...
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
_headerImgView = [[UIImageView alloc] initWithFrame: headerImgFrame];
_headerImgView.image = [UIImage imageNamed: @"test.png"];
_headerImgView.contentMode = UIViewContentModeCenter;
_headerImgView.autoresizingMask = UIViewAutoresizingNone;
_headerImgView.layer.masksToBounds = YES;
UIView *bgView = [[UIView alloc] init];
bgView.backgroundColor = [UIColor whiteColor];
tableView.backgroundView = bgView;
[bgView release];
[tableView.backgroundView addSubview: _headerImgView];
[_headerImgView release];
}
- (void)scrollViewDidScroll: (UIScrollView *)scrollView {
CGRect newFrame = CGRectMake(headerImgFrame.origin.x, headerImgFrame.origin.y,
headerImgFrame.size.width, headerImgFrame.size.height - scrollView.contentOffset.y);
_headerImgView.frame = newFrame;
}