基于@布赖恩建议我做了这个代码:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat height = navigationBar.frame.size.height;
CGFloat y = scrollView.bounds.origin.y;
if (y <= 0) {
CGRect frame = navigationBar.frame;
frame.origin.y = 0;
navigationBar.frame = frame;
} else if (tableView.contentSize.height > tableView.frame.size.height) {
CGFloat diff = height - y;
CGRect frame = navigationBar.frame;
frame.origin.y = -y;
navigationBar.frame = frame;
CGFloat origin = 0;
CGFloat h = height; // height of the tableHeaderView
if (diff > 0) {
origin = diff;
h = y;
}
frame = tableView.frame;
frame.origin.y = origin;
frame.size.height = tableView.superview.frame.size.height - origin;
tableView.frame = frame;
CGRect f = CGRectMake(0, 0, tableView.frame.size.width, h);
UILabel* label = [[UILabel alloc] initWithFrame:f];
tableView.tableHeaderView = label;
[label release];
}
}
我的代码有一个UITableView但应与任何滚动组件工作。如果除了navigationBar和UIScrollView子类之外还有其他组件,则应该更改可滚动组件高度的计算方式。这样的事情:
frame.size.height = tableView.superview.frame.size.height - origin - otherComponentsHeight;
我需要添加一个愚蠢tableHeaderView具有所需的行为。问题是,当scrollViewDidScroll:被调用时,内容有偏移量,但移动Safari中的可见性是内容不会滚动,直到导航条完全消失。我首先尝试将contentOffset.y更改为0,但显然它不起作用,因为所有代码都依赖于滚动机制。所以我只是添加了一个tableHeaderView,它的高度恰好是滚动的偏移量,所以头部永远不会被看到,并且内容似乎不会滚动,直到导航条完全消失。
如果您不添加哑表tableHeaderView,则可滚动组件会显示在导航栏后面滚动。
随着tableHeaderView,所述滚动组件实际上是滚动(如图滚动条),但由于存在tableHeaderView其高度恰好比滚动偏离相同的,可滚动内容似乎不可以滚动,直到完全的导航栏消失:
类似的问题:HTTP://计算器。com/questions/21929220/show-hide-uitoolbar-match-finger-movement-exactly-as-in-for-example-ios7-s这是非常微妙的做它它像safari .... – Fattie 2014-02-28 20:39:09