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];
}];
}];
}