swift 使用MAGearRefreshControl控件刷新
2015-07-17 15:27
176 查看
class ThridViewController:UIViewController, UITableViewDataSource,UITableViewDelegate,MAGearRefreshDelegate { var _tableView:UITableView! var refreshControlView:MAGearRefreshControl! var isLoading =false overridefunc viewDidLoad() { super.viewDidLoad(); self.navigationController?.navigationBar.translucent = false var screeSize:CGSize =UIScreen.mainScreen().bounds.size _tableView =UITableView(frame: CGRectMake(0,0, screeSize.width, screeSize.height), style: .Plain) _tableView.dataSource =self _tableView.delegate =self self.view.addSubview(_tableView) refreshControlView =MAGearRefreshControl(frame: CGRectMake(0, -_tableView.bounds.height,self.view.frame.width,_tableView.bounds.height)) refreshControlView.backgroundColor = UIColor.initRGB(234, g:234, b: 234) refreshControlView.addInitialGear(nbTeeth:12, color:UIColor.initRGB(40, g:40, b: 40), radius:16) refreshControlView.addLinkedGear(0, nbTeeth:16, color: UIColor.initRGB(80, g:80, b: 80).colorWithAlphaComponent(0.8), angleInDegree:30) refreshControlView.addLinkedGear(0, nbTeeth:32, color: UIColor.initRGB(104, g:104, b: 104).colorWithAlphaComponent(0.4), angleInDegree:190) refreshControlView.addLinkedGear(1, nbTeeth:40, color: UIColor.initRGB(104, g:104, b: 104).colorWithAlphaComponent(0.4), angleInDegree: -30) refreshControlView.addLinkedGear(2, nbTeeth:24, color: UIColor.initRGB(80, g:80, b: 80).colorWithAlphaComponent(0.8), angleInDegree: -190) refreshControlView.addLinkedGear(3, nbTeeth:10, color: UIColor.initRGB(80, g:80, b: 80), angleInDegree:40) refreshControlView.setMainGearPhase(0) refreshControlView.delegate =self refreshControlView.barColor =UIColor.initRGB(200, g:200, b: 200) _tableView.addSubview(refreshControlView) } func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int { return20; } func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell { var identiferString ="Cell_\(indexPath.row)" var cell :UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(identiferString)as? UITableViewCell if(cell ==nil){ cell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier: identiferString) } cell?.textLabel?.text ="Row \(indexPath.row)" return cell!; } //MARK: - UIScrollViewDelegate protocol conformance func scrollViewDidScroll(scrollView:UIScrollView) { refreshControlView.MAGearRefreshScrollViewDidScroll(scrollView) } func scrollViewDidEndDragging(scrollView:UIScrollView, willDecelerate decelerate:Bool) { refreshControlView.MAGearRefreshScrollViewDidEndDragging(scrollView) } overridefunc didRotateFromInterfaceOrientation(fromInterfaceOrientation:UIInterfaceOrientation) { refreshControlView.frame =CGRectMake(0, -_tableView.bounds.height,self.view.frame.size.width,_tableView.bounds.size.height) } //MARK: - MAGearRefreshDelegate protocol conformance func MAGearRefreshTableHeaderDataSourceIsLoading(view:MAGearRefreshControl) -> Bool { returnisLoading } func MAGearRefreshTableHeaderDidTriggerRefresh(view:MAGearRefreshControl) { refresh() } func refresh(){ isLoading =true // -- DO SOMETHING AWESOME (... or just wait 3 seconds) -- // This is where you'll make requests to an API, reload data, or process information var delayInSeconds =0.6 var popTime =dispatch_time(DISPATCH_TIME_NOW,Int64(delayInSeconds * Double(NSEC_PER_SEC))) dispatch_after(popTime,dispatch_get_main_queue()) { () ->Void in // When done requesting/reloading/processing invoke endRefreshing, to close the control self.isLoading =false self.refreshControlView.MAGearRefreshScrollViewDataSourceDidFinishedLoading(self._tableView) } } }
相关文章推荐
- swift 中navigationBar颜色设置
- Swift2.0语言教程之Swift2.0语言中的标准函数
- Swift2.0语言教程之Swift2.0语言中的标准函数
- Swift 中UITabBarController使用方法
- Swift_String>SubstringWithRange用法
- swift2 控制流
- swift 基本文件读写
- Swift2.0语言教程之函数的返回值与函数类型
- Swift2.0语言教程之函数的返回值与函数类型
- #openstack-meeting: swift(2015-07-15)
- Swift2.0语言教程之函数的返回值与函数类型
- Swift2.0语言教程之Swift2.0语言中的标准函数
- 集成支付宝接口 swift
- 【沙龙干货】如何在实际工程中使用Swift开发?
- 【沙龙干货】Swift是花拳绣腿吗?开发语言与职业生涯如何选择?
- 【原创IOS开发】swift使用SDWebImages
- IOS swift多点触控
- Swif语法基础 要点归纳(一)
- Swift面向对象基础(中)——Swift中的方法
- Swift中NSDictionaryOfVariableBindings的替代方案