mat*_*ven 18
您的屏幕截图并没有立即注意到这一点,但我相信您希望该标题工具栏在用户滚动时向上滑动,对吧?(我建议澄清那部分)
您可以通过几种方式执行此操作,在所有这些方法中,您将必须实现自己的滚动逻辑,这意味着标题工具栏会根据您滚动的位置向上滑动多少.那就是说,这是怎么做的:
1.如果您正在使用UITableView,我假设您已将视图控制器设置为其delegate.既然UITableView是UIScrollView已经的子类,只需将其添加UIScrollViewDelegate到视图控制器即可.这将为我们提供滚动事件.你想要做你的逻辑scrollViewDidScroll:.
2.如果您只是使用UIScrollView,只需将视图控制器设置为其委托,实现UIScrollViewDelegate并执行您的逻辑scrollViewDidScroll:.
也就是说,您的代码可能如下所示:
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint scrollPos = scrollView.contentOffset;
if(scrollPos.y >= 40 /* or CGRectGetHeight(yourToolbar.frame) */){
// Fully hide your toolbar
} else {
// Slide it up incrementally, etc.
}
}
Run Code Online (Sandbox Code Playgroud)
无论如何,希望我帮助.
如果您已正确设置委托,则表格将在滚动时调用scrollViewDidScroll:.
所以在你的控制器中,你可以添加如下内容:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y >0) //means that the user began to scroll down the table
{
[UIView animateWithDuration:0.4 animations:^{
//animations you want to perform
}];
}
}
Run Code Online (Sandbox Code Playgroud)
在这里我实现了 UIView Hide / Show 当 tableview 滚动时的代码。当 tableview 向下滚动时 UIView 被隐藏,当向上滚动时 UIView 显示。我希望它对你有用......!
第 1 步:- 在 .h 文件中创建一个属性
@property (nonatomic) CGFloat previousContentOffset;
Run Code Online (Sandbox Code Playgroud)
第 2 步:- 在 scrollViewDidScroll 方法中写下此代码。
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat currentContentOffset = scrollView.contentOffset.y;
if (currentContentOffset > self.previousContentOffset) {
// scrolling towards the bottom
[self.subButtonView setHidden:YES];
} else if (currentContentOffset < self.previousContentOffset) {
// scrolling towards the top
[self.subButtonView setHidden:NO];
}
self.previousContentOffset = currentContentOffset;
}
Run Code Online (Sandbox Code Playgroud)