我想在iPhone上创建类似于App Store应用视图的视图:
http://cl.ly/image/0Q1h273v3C00
基本上向下滚动时,标题的一部分仍然固定在顶部:
http://cl.ly/image/3m0I3Y0t1901
这是我尝试过的方法,但它没有按预期工作:
然后,我只是实现以下方法:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// Keeping the menu always visible when user scrolls
// 155 is the original y position of the menu (UISegmentedControl here)
if (scrollView.contentOffset.y > 155) {
self.menuView.frame = CGRectMake(0,
scrollView.contentOffset.y,
self.menuView.frame.size.width,
self.menuView.frame.size.height);
}
else {
self.menuView.frame = CGRectMake(0,
155,
self.menuView.frame.size.width,
self.menuView.frame.size.height);
}
}
菜单按照我的要求保持在最高位置,但仍然没有按预期工作:
滚动时,我的tableView部分标题与菜单重叠。我找到的唯一修复是使用以下代码将标题图层放在顶部:
self.tableView.tableHeaderView.layer.zPosition = MAXFLOAT;
但是现在滚动条隐藏在标题后面,所以我对此也不满意 我还尝试在viewDidLoad和... viewForHeaderInSection
中使用此调用[self.tableView bringSubviewToFront:self.tableView.tableHeaderView];
但它只是不起作用,因为节标题总是在tableView标题之后添加,我还没有找到方法知道何时添加节标题,所以我可以将它们放在tableView标题。
有没有人对如何解决我面临的问题有任何想法,或采取不同的方法?
PS:Youtube对于频道视图来说有点相同,但他们的解决方案并不像Apple那样好,因为如果你开始从标题滚动,你就无法移动内容。
感谢您的帮助!