iOS tableView滑动隐藏/显示tabbar
2015-10-23 15:30
495 查看
在需要滑动隐藏/显示的页面中:
@property(nonatomic,assign)CGFloat historyY;
#pragma mark Delegate
//设置滑动的判定范围
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout
CGPoint *)targetContentOffset
{
if (historyY+20<targetContentOffset->y)
{
[self
setTabBarHidden:YES];
}
else if(historyY-20>targetContentOffset->y)
{
[self
setTabBarHidden:NO];
}
historyY=targetContentOffset->y;
}
//隐藏显示tabbar
- (void)setTabBarHidden:(BOOL)hidden
{
UIView *tab =
self.tabBarController.view;
CGRect tabRect=self.tabBarController.tabBar.frame;
if ([tab.subviews
count] < 2) {
return;
}
UIView *view;
if ([[tab.subviews
objectAtIndex:0]
isKindOfClass:[UITabBar
class]]) {
view = [tab.subviews
objectAtIndex:1];
} else {
view = [tab.subviews
objectAtIndex:0];
}
if (hidden) {
view.frame = tab.bounds;
tabRect.origin.y=[[UIScreen
mainScreen]
bounds].size.height+self.tabBarController.tabBar.frame.size.height;
} else {
view.frame =
CGRectMake(tab.bounds.origin.x, tab.bounds.origin.y,
tab.bounds.size.width, tab.bounds.size.height);
tabRect.origin.y=[[UIScreen
mainScreen]
bounds].size.height-self.tabBarController.tabBar.frame.size.height;
}
[UIView
animateWithDuration:0.5f
animations:^{
self.tabBarController.tabBar.frame=tabRect;
}completion:^(BOOL finished) {
}];
}
@property(nonatomic,assign)CGFloat historyY;
#pragma mark Delegate
//设置滑动的判定范围
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout
CGPoint *)targetContentOffset
{
if (historyY+20<targetContentOffset->y)
{
[self
setTabBarHidden:YES];
}
else if(historyY-20>targetContentOffset->y)
{
[self
setTabBarHidden:NO];
}
historyY=targetContentOffset->y;
}
//隐藏显示tabbar
- (void)setTabBarHidden:(BOOL)hidden
{
UIView *tab =
self.tabBarController.view;
CGRect tabRect=self.tabBarController.tabBar.frame;
if ([tab.subviews
count] < 2) {
return;
}
UIView *view;
if ([[tab.subviews
objectAtIndex:0]
isKindOfClass:[UITabBar
class]]) {
view = [tab.subviews
objectAtIndex:1];
} else {
view = [tab.subviews
objectAtIndex:0];
}
if (hidden) {
view.frame = tab.bounds;
tabRect.origin.y=[[UIScreen
mainScreen]
bounds].size.height+self.tabBarController.tabBar.frame.size.height;
} else {
view.frame =
CGRectMake(tab.bounds.origin.x, tab.bounds.origin.y,
tab.bounds.size.width, tab.bounds.size.height);
tabRect.origin.y=[[UIScreen
mainScreen]
bounds].size.height-self.tabBarController.tabBar.frame.size.height;
}
[UIView
animateWithDuration:0.5f
animations:^{
self.tabBarController.tabBar.frame=tabRect;
}completion:^(BOOL finished) {
}];
}
相关文章推荐
- 运行百度语音识别官方iOS demo报错: load offline engine failed: 4001
- iOS--格式化日期时间
- iOS 开发中如何使用半透明模糊效果
- iOS开发—AFNetworking的使用
- iOS开发>学无止境 - 委托模式
- iOS三方-MJRefresh的使用
- iOS 日志自动上报
- iOS---开发时间戳与时间,时区的转换,汉字与UTF8,16进制的转换
- iOS---标准时间与时间戳相互转换
- iOS子视图中找到特定类型的视图
- 触摸点为scrollview上的子控件时,scrollview不能滚动(iOS8)
- iOS开发系列--地图与定位
- iOS-如何使用symbolicatecrash
- 开始iOS 7中自动布局教程(二)
- iOS开发必备--环境变量配置(Debug & Release)
- 开始iOS 7中自动布局教程(一)
- iOS 消息推送原理及实现Demo
- IOS导航栏颜色渐变与常用属性
- iOS 一个简单的单例
- iOS7View被导航栏遮挡问题的解决