swift 使用MAGearRefreshControl控件刷新

来源:互联网 发布:pk10网站源码 编辑:程序博客网 时间:2024/06/07 07:17

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)                    }          }        }


0 0
原创粉丝点击