如何实现下滑tableview时隐藏nav+tabbar

 我来答
huanglenzhi
2016-02-29 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117525 获赞数:517229
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
//

// LQXViewController.m
// LQXCallBackBar
//
// Created by 刘祺旭 on 15/4/27.
// Copyright (c) 2015年 CSDN探花花花. All rights reserved.
//

#import "LQXViewController.h"
#define LQXWidth self.view.bounds.size.width
#define LQXHeight self.view.bounds.size.height
#define LQXData [NSString stringWithFormat:@"随机数据---%d", arc4random_uniform(1000000)]

@interface LQXViewController ()<uitableviewdelegate,uitableviewdatasource>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *dataArray;
@property (nonatomic, assign) BOOL hidden;
@property (nonatomic, assign) BOOL scrollUporDown;
@end

@implementation LQXViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.tabBarController.tabBar.frame = CGRectMake(0, LQXHeight - 40, LQXWidth, 40);
UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, LQXWidth, 20)];

statusBarView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"首页--标题栏.png"]];

[self.view addSubview:statusBarView];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];

self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, LQXWidth, LQXHeight - 20) style:0];
self.tableView.bounces = YES
;
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.rowHeight = 135;
self.tableView.userInteractionEnabled = YES;
self.tableView.showsHorizontalScrollIndicator = NO;
self.tableView.showsVerticalScrollIndicator = NO;
self.dataArray = [NSMutableArray array];
for (int i = 0; i< 100; i++) {
[self.dataArray addObject:LQXData];
}
[self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
// Return the number of rows in the section.
return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *str = @"reuse";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:str];
}
cell.textLabel.text = self.dataArray[indexPath.row];
return cell;

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if ([scrollView isEqual:self.tableView]) {
static float newy = 0;
static float oldy = 0;
newy = scrollView.contentOffset.y ;
if (newy != oldy ) {
if (newy > oldy) {
self.scrollUporDown = YES;
}else if(newy < oldy){
self.scrollUporDown = NO;
}
oldy = newy;
}
if (_scrollUporDown == YES) {
self.hidden = YES;
[UIView animateWithDuration:0.5 animations:^{
self.navigationController.navigationBar.frame = CGRectMake(0, -40, LQXWidth, 40);
self.tabBarController.tabBar.frame = CGRectMake(0 , LQXHeight + 40, LQXWidth, 40);
}];

}
else if (_scrollUporDown == NO) {
if (self.hidden == YES) {
[UIView animateWithDuration:0.5 animations:^{
self.navigationController.navigationBar.frame = CGRectMake(0, 20, LQXWidth, 40);
self.tabBarController.tabBar.frame = CGRectMake(0 , LQXHeight , LQXWidth, 40);
}];

self.hidden = NO;
}
}

}
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
</uitableviewdelegate,uitableviewdatasource>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式