iOS Swift&OC 模仿主流App 实现滑动视图隐藏导航栏
来源:互联网 发布:淘宝详情页怎么加链接 编辑:程序博客网 时间:2024/06/05 14:20
简单直接上图上代码 -.- 一个GIF图5M?
@property (nonatomic, strong) UITableView *tableViewScroll;@property (nonatomic, assign) double recordDistance; //记录滑动的距离@property (nonatomic, strong) UIView *customView;@property (nonatomic, strong) UIButton *btn;
创建所需要的视图
- (UITableView *)tableViewScroll{ if (_tableViewScroll == nil) { _tableViewScroll = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight) style:UITableViewStylePlain]; _tableViewScroll.delegate = self; _tableViewScroll.dataSource = self; [_tableViewScroll registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier]; } return _tableViewScroll;}
- (UIView *)customView{ if (_customView == nil) { _customView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, screenWidth, 30)]; _customView.backgroundColor = [UIColor lightGrayColor]; } return _customView;}
- (UIButton *)btn{ if (_btn == nil) { _btn = [UIButton buttonWithType:UIButtonTypeCustom]; _btn.frame = CGRectMake(screenWidth - 70, 5, 40, 20); [_btn setTitle:@"关注" forState:UIControlStateNormal]; _btn.titleLabel.font = [UIFont systemFontOfSize:13]; _btn.backgroundColor = [UIColor greenColor]; } return _btn;}
关键在于scrollView协议方法中的处理
// Objective-C- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ // 记录滑动距离 self.recordDistance = scrollView.contentOffset.y; NSLog(@"histroy_y ======== %lf", self.recordDistance);}// Swiftfunc scrollViewDidEndDecelerating(scrollView: UIScrollView) { self.recordDistance = scrollView.contentOffset.y }
// Objective-C- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ NSLog(@"y ======= %lf", scrollView.contentOffset.y); scrollView.contentOffset.y > self.recordDistance ? scrollView.contentOffset.y < self.recordDistance ? [self.navigationController setNavigationBarHidden:NO animated:YES]:[self.navigationController setNavigationBarHidden:YES animated:YES] : [self.navigationController setNavigationBarHidden:NO animated:YES];}// Swiftfunc scrollViewDidScroll(scrollView: UIScrollView) { scrollView.contentOffset.y > self.recordDistance ? scrollView.contentOffset.y < self.recordDistance ? self.navigationController?.setNavigationBarHidden(false, animated: true):self.navigationController?.setNavigationBarHidden(true, animated: true) : self.navigationController?.setNavigationBarHidden(false, animated: true); }
省略了tableview相关的代码
在viewDidload中
[self.view addSubview:self.tableViewScroll]; [self.navigationController.navigationBar addSubview:self.customView]; [self.customView addSubview:self.btn]; self.title = @"这是一个测试页"; self.navigationController.navigationBar.barTintColor = [UIColor lightGrayColor];
觉得还可以请点个赞, 我要申请微博加V. 点个赞吧客官 -.- 哈哈哈
5 0
- iOS Swift&OC 模仿主流App 实现滑动视图隐藏导航栏
- iOS 滑动隐藏导航栏
- swift中关于隐藏导航栏的和侧别往右滑动实现同样的pop效果
- 滑动逐渐隐藏导航栏的实现
- iOS Navigation Bar 导航栏折腾记 (Swift&OC)
- iOS Navigation Bar 导航栏折腾记 (Swift&OC)
- iOS开发上下滑动UIScrollview隐藏或者显示导航栏
- iOS 关于滑动返回隐藏导航栏的问题
- iOS UITableView表视图滚动隐藏UINavigationController导航栏
- IOS OC Navigation 导航条动态隐藏
- 导航栏滑动显示隐藏
- 一句代码实现标题栏、导航栏滑动隐藏
- 一句代码实现标题栏、导航栏滑动隐藏
- AppBarLayout+TabLayout+RecyclerView实现滑动隐藏导航栏。
- ios 上滑隐藏导航下拉显示导航栏实现
- 含有导航栏的视图里tableView的坐标问题(swift代码理论和OC相通)
- iOS 隐藏导航栏
- 隐藏导航栏iOS
- 后缀数组模版
- MATLAB中只删除本地文件夹里面的灰度图
- linux-Centos-7-64位:3、 firewalld 配置
- PAT-B 1008. 数组元素循环右移问题
- 深入理解redis_memcached失效原理
- iOS Swift&OC 模仿主流App 实现滑动视图隐藏导航栏
- Qt 错误"new types may not be defined in a return type" error
- android,闹钟定时功能,实现过程
- 51nod 1232:完美数
- Windows核心编程之线程创建
- HttpURLConnection +HttpClient
- 三门问题的误区
- 无法对视图创建索引,因为该视图未绑定到架构 SQLServer
- MATLAB相关函数