I'd like to have an effect like the foursquare venue page where the navigation bar starts clear, then becomes opaque when the top cell in the table scrolls out of view. The twitter app has a similar effect in the profile tab.
我希望有一个像导航栏开始清晰的foursquare场所页面的效果,然后当表格中的顶部单元格滚出视图时变得不透明。 Twitter应用程序在配置文件选项卡中具有类似的效果。
How would this be accomplished? Is there a way to know when a cell goes out of view (the opposite of tableView:willDisplayCell:forRowAtIndexPath:
) Or should should I check the scroll position of the table and make changes when the scroll position is at a certain value?
这将如何实现?有没有办法知道一个单元格何时离开视图(与tableView相反:willDisplayCell:forRowAtIndexPath :)或者我应该检查表格的滚动位置并在滚动位置达到某个值时进行更改?
Thanks
谢谢
1 个解决方案
#1
0
Try this code, declare an ivar named lastOffset of type CGFloat.
试试这段代码,声明一个名为lastOffset的类型为CGFloat的ivar。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat distance = lastOffset - scrollView.contentOffset.y;
lastOffset = scrollView.contentOffset.y;
CGFloat barHeight = self.navigationController.navigationBar.frame.size.height;
if (lastOffset > - barHeight) {
[UIView animateWithDuration:0.2 animations:^{
self.navigationController.navigationBar.frame = CGRectOffset(self.navigationController.navigationBar.frame, 0.0f, distance);
}];
}
}
#1
0
Try this code, declare an ivar named lastOffset of type CGFloat.
试试这段代码,声明一个名为lastOffset的类型为CGFloat的ivar。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat distance = lastOffset - scrollView.contentOffset.y;
lastOffset = scrollView.contentOffset.y;
CGFloat barHeight = self.navigationController.navigationBar.frame.size.height;
if (lastOffset > - barHeight) {
[UIView animateWithDuration:0.2 animations:^{
self.navigationController.navigationBar.frame = CGRectOffset(self.navigationController.navigationBar.frame, 0.0f, distance);
}];
}
}