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);
            }];
    
        });
    
    }
  • 相关阅读:
    UML_状态图
    UML_时序图
    UML_类图
    浅谈依赖注入
    MyEclipse_搭建SSH框架
    AOP:面向切面编程
    工厂模式
    (转)oracle使用expdp、impdp和exp、imp导入导出表及表结构
    oracle exp 和 imp 数据和表结构互相独立导出导入
    oracle 清空当前用户所有对象
  • 原文地址:https://www.cnblogs.com/yintingting/p/5468489.html
Copyright © 2011-2022 走看看