UIScrollView滚动时隐藏底部导航栏问题
2015-08-19 22:08
507 查看
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"开始滚动");
int currentPostion = scrollView.contentOffset.y;
if (currentPostion -
_lastPosition > 20 && currentPostion >0) {
_lastPosition = currentPostion;
NSLog(@"ScrollUp now");
self.tabBarController.tabBar.hidden
=YES;
[self.navigationControllersetNavigationBarHidden:YESanimated:YES];
}
else
if ((_lastPosition - currentPostion >20) && (currentPostion <= scrollView.contentSize.height-scrollView.bounds.size.height-20)
)
{
_lastPosition = currentPostion;
NSLog(@"ScrollDown now");
self.tabBarController.tabBar.hidden
=NO;//隐藏时,没有动画效果
[self.navigationControllersetNavigationBarHidden:NOanimated:YES];
}
}
转载自:http://blog.csdn.net/caryaliu/article/details/7907196
自:在我的工程中,我是把 _lastPosition = 0; 然后把那个 25 改成了 160
有时候我们需要检测当前UIScrollView的滑动方向来做出相应的处理,可以借助UIScrollView的delegate函数来实现, 下面的例子可以检测到UIScrollview当前是向上滑动还是向下滑动:
[cpp] view
plaincopy
int _lastPosition; //A variable define in headfile
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
int currentPostion = scrollView.contentOffset.y;
if (currentPostion - _lastPosition > 25) {
_lastPosition = currentPostion;
NSLog(@"ScrollUp now");
}
else if (_lastPosition - currentPostion > 25)
{
_lastPosition = currentPostion;
NSLog(@"ScrollDown now");
}
}
25 可以是任意数字,可根据自己的需要来设定。
{
NSLog(@"开始滚动");
int currentPostion = scrollView.contentOffset.y;
if (currentPostion -
_lastPosition > 20 && currentPostion >0) {
_lastPosition = currentPostion;
NSLog(@"ScrollUp now");
self.tabBarController.tabBar.hidden
=YES;
[self.navigationControllersetNavigationBarHidden:YESanimated:YES];
}
else
if ((_lastPosition - currentPostion >20) && (currentPostion <= scrollView.contentSize.height-scrollView.bounds.size.height-20)
)
{
_lastPosition = currentPostion;
NSLog(@"ScrollDown now");
self.tabBarController.tabBar.hidden
=NO;//隐藏时,没有动画效果
[self.navigationControllersetNavigationBarHidden:NOanimated:YES];
}
}
转载自:http://blog.csdn.net/caryaliu/article/details/7907196
自:在我的工程中,我是把 _lastPosition = 0; 然后把那个 25 改成了 160
有时候我们需要检测当前UIScrollView的滑动方向来做出相应的处理,可以借助UIScrollView的delegate函数来实现, 下面的例子可以检测到UIScrollview当前是向上滑动还是向下滑动:
[cpp] view
plaincopy
int _lastPosition; //A variable define in headfile
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
int currentPostion = scrollView.contentOffset.y;
if (currentPostion - _lastPosition > 25) {
_lastPosition = currentPostion;
NSLog(@"ScrollUp now");
}
else if (_lastPosition - currentPostion > 25)
{
_lastPosition = currentPostion;
NSLog(@"ScrollDown now");
}
}
25 可以是任意数字,可根据自己的需要来设定。
相关文章推荐
- LightOJ 题目1427 - Substring Frequency (II)(AC自动机)
- 实现UITableView循环利用
- STL使用:deque双端队列
- 8.18 [LeetCode 52] N-Queens II
- UI_04 事件处理
- uva 11248 Frequency Hopping (最大流)
- HDU 3836--Equivalent Sets【求有向图最少增加多少边使图强连通 && Scc缩点新建图】
- priority_queue优先队列容器
- UVA 694-The Collatz Sequence
- GUID全球唯一标识
- GUID全球唯一标识
- ios UIButton的图片和文字位置
- iOS UI基础-2.0按钮操作与形变
- iOS ui 学习 1-2天的笔记
- UITableViewController
- 利用media query写响应式布局
- The Unique MST 判断生成树是否唯一
- HDU 3698 Let the light guide us
- UDKtoUE4Tool-UDKUE3资源移植UE4工具
- uestc 360(区间合并)