IOS 添加下拉刷新

1,添加控件

//添加下拉刷新控件
-(void)setupRefresh{
    UIRefreshControl*refControl=[[UIRefreshControl alloc]init];
    [refControl addTarget:self action:@selector(RefreshData:) forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview:refControl];
    [refControl beginRefreshing];
    [self RefreshData:refControl];
}
-(void)RefreshData:(UIRefreshControl*)control{
    DLog(@"刷新数据");
    //[control beginRefreshing];
    [self.tableView reloadData];
    [control endRefreshing];
}

2,刷新成功顶部提示

//显示刷新提示标签
-(void)showNavigationAlert:(NSString*)alertTitle{
    UILabel*refreshIndicatorLab = [UILabel new];
    refreshIndicatorLab.textAlignment = NSTextAlignmentCenter;
   // refreshIndicatorLab.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@""]];
    refreshIndicatorLab.backgroundColor = [UIColor lightGrayColor];
    refreshIndicatorLab.font = [UIFont systemFontOfSize:10];
    refreshIndicatorLab.text = alertTitle;
    refreshIndicatorLab.width = self.navigationController.view.width;
    refreshIndicatorLab.height = LWLWindowsW/20;
    refreshIndicatorLab.x = 0;
    refreshIndicatorLab.y = [UIApplication sharedApplication].statusBarFrame.size.height + self.navigationController.navigationBar.height - refreshIndicatorLab.height;
    [self.navigationController.view insertSubview:refreshIndicatorLab belowSubview:self.navigationController.navigationBar];
    [UIView animateWithDuration:1.0f animations:^{
        // 使用更改transform来实现
refreshIndicatorLab.transform = CGAffineTransformMakeTranslation(0, refreshIndicatorLab.height);
    } completion:^(BOOL finished) {
    [UIView animateWithDuration:0.5 delay:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        // 恢复位置
    refreshIndicatorLab.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
         [refreshIndicatorLab removeFromSuperview];
    }];
    }];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值