你需要UI图像视图 to UI滚动视图 内容插入并将顶部插入设置为大于零。
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UIImage *topImage = [UIImage imageNamed:@"photo"];
topImage.frame = CGRectMake(0, -topImage.frame.size.height, topImage.frame.size.width, topImage.frame.size.height);
[scroll addSubview:topImage];
self.contentInset = UIEdgeInsetsMake(topImage.frame.size.height, 0, 0, 0);
在那组之后UI滚动视图's 内容偏移量像这样
scroll.contentOffset = CGPointMake(0, topImage.frame.size.height);
所以你有UI滚动视图里面有图像。现在你只需要添加delegate到 UIScrollView 并等待- (void)scrollViewDidScroll:(UIScrollView *)scrollView
。调用此方法后立即调整图像大小并更改 contentInset。
您也可以应用此建议UI表格视图类似的方式,或创建类别UI滚动视图.
我还建议您阅读该项目的代码https://github.com/samvermette/SVPullToRefresh https://github.com/samvermette/SVPullToRefresh。这也是关于UI表格视图并将视图添加到其顶部