zoukankan      html  css  js  c++  java
  • 自定义刷新控件的实现原理

    - (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);
            }];
    
        });
    
    }
  • 相关阅读:
    Discuz上传错误
    Node.js程序在node-windows中不能运行
    如何开机就启动node.js程序
    创建并发布node.js module
    Windows下安装mongodb
    Grunt学习一:使用grunt创建jquery plugin.
    如何用 Jquery实现OuterHtml
    VS2008中生成DLL项目
    C++变量未进行初始化时的默认值
    C++的四种初始化形式以及类型转换
  • 原文地址:https://www.cnblogs.com/yintingting/p/5468489.html
Copyright © 2011-2022 走看看