自定义刷新控件的实现原理
2016-05-07 15:48
239 查看
- (void)viewDidLoad { [super viewDidLoad]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, -30, self.view.bounds.size.width, 30); [button setTitle:@"下拉刷新" forState:UIControlStateNormal]; [self.view addSubview:button]; button.backgroundColor = [UIColor redColor]; self.refreshButton = button; [self.tableView addSubview:button]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ NSLog(@"%f",scrollView.contentOffset.y); if (scrollView.contentInset.top == 30) return; if (scrollView.contentOffset.y <= -30) { [self.refreshButton setTitle:@"松开刷新" forState:UIControlStateNormal]; } else{ [self.refreshButton setTitle:@"下拉刷新" forState:UIControlStateNormal]; } } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ if (scrollView.contentOffset.y <= -30) { [UIView animateWithDuration:0.5 animations:^{ [self.refreshButton setTitle:@"正在刷新" forState:UIControlStateNormal]; scrollView.contentInset = UIEdgeInsetsMake(30, 0, 0, 0); }]; } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [UIView animateWithDuration:0.5 animations:^{ scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); }]; }); }
相关文章推荐
- Linux设备模型(Linux设备驱动程序)
- JAVA泛型中? T K V E等代表的意思
- hihoCoder 数论五·欧拉函数
- Btree(B-树)---C++
- win10系统中ASP.NET(VS2013)和MATLAB混编,调用MATLAB生成的.dll文件
- 【Leetcode】:326. Power of Three 问题 in JAVA
- 产品经理的黑魔法系列文章合集
- 终于解决了excel操作及cspreadsheet.h问题
- iOS 网络请求 笔记
- Spring hibernatecallback学习
- KJHttp框架使用讲解
- 高校采购招标信息管理系统
- Amazon Employee Access 数据分析报告(python)
- BM算法详解
- 集群化部署定时任务
- listview的九大重要属性
- 如何检测AudioRecord是否被第三方管理应用给禁用了,附上demo
- 11周 5 项目 - 摩托车继承自行车和机动车
- 基于jquery实现图片放大功能
- Android getScrollX()详解