一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。
OC Control Empty(加载动画-空白页)下载链接
Swift 也可以调用OC封装的Empty(加载动画-空白页)下载链接
效果
使用
//写到viewModel
@property (nonatomic, assign) BOOL loading;
//写在网络数据成功
self.loading = NO;
//写在网络数失败的地方
self.loading = NO;
//写在buildsubview里面初始化
self.viewModel.loading = YES;
//下载成功和失败的获取数据代理,在刷新tableview reload这句话下面
[self.collectionView reloadEmptyDataSet];
,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate
//写在初始化tableview哪里
self.collectionView.emptyDataSetSource = self;
self.collectionView.emptyDataSetDelegate = self;
#pragma mark 空白页代理方法
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
return self.viewModel.loading?[UIImage loadGifWithImageName:@"nahuoLoading"]:[UIImage imageNamed:@"empty-out-of-service-area"];
}
// 图片的动画效果(默认为关闭,需要调用代理方法emptyDataSetShouldAnimateImageView进行开启)
- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView {
//Y轴旋转
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform"];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)];
animation.duration = 0.25;
animation.cumulative = YES;
animation.repeatCount = MAXFLOAT;
return animation;
}
// 是否开启动画
- (BOOL)emptyDataSetShouldAnimateImageView:(UIScrollView *)scrollView {
return self.viewModel.loading;
}
//设置友好图片提示偏移位置
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{
return self.sliderCellisShow?0:-270;
}
#pragma mark - DZNEmptyDataSetDelegate
// 点击中间的图片和文字时调用
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view{
self.viewModel.loading = YES;
[self.collectionView reloadEmptyDataSet];
[self.viewModel <#获取网络数据#>];
}