(因为有加载的图片,所以想要看到最完整的效果,请点击 https://github.com/liumude/LoadingView 下载 iOS开发交流群:301058503(如果不是开发者,做广告的就不用进了,因为迟早都被踢))
**
此加载页做了优化处理:在网络状态良好的情况下(1秒请求完毕),不会显示,防止闪现。 有可能是1.1秒请求完毕,那样也会闪现,这里也做了处理,在显示加载页之后,至少0.5秒后才会隐藏(如果在显示之后的0.5秒内请求完毕,则显示0.5秒隐藏,如果在显示之后的0.5秒后请求完毕,则请求完毕之后隐藏)
**
- .h文件
#import <UIKit/UIKit.h>
typedef enum : NSUInteger {
RequestLoading,
RequestSuccess,
RequestFaild,
} RequestResult;
@interface JZLoadingViewPacket : UIView
- (void)showWithTitle:(NSString *)title result:(RequestResult)result;
- (void)jz_hide;
+ (JZLoadingViewPacket *)shareInstance;
+ (void)showWithTitle:(NSString *)title result:(RequestResult)result addToView:(UIView *)selfView;
@end
- .m文件
#import "JZLoadingViewPacket.h"
@interface JZLoadingViewPacket ()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIView *bgView;
//控制显示后再隐藏的时间间隔>=1秒,提高用户体验
@property (nonatomic, assign) BOOL isShow;
@property (nonatomic, assign) BOOL isUseHiden;
@end
@implementation JZLoadingViewPacket
- (void)showWithTitle:(NSString *)title result:(RequestResult)result {
_isShow = NO;
_isUseHiden = NO;
self.hidden = NO;
self.backgroundColor = [UIColor clearColor];
self.titleLabel.text = title;
if (result == RequestLoading) {
self.imageView.image = [UIImage imageNamed:@"rotationImage"];
}else if (result == RequestSuccess) {
self.imageView.image = [UIImage imageNamed:@"requestSuccess"];
}else if (result == RequestFaild) {
self.imageView.image = [UIImage imageNamed:@"networkFaild"];
}
[self.imageView.layer removeAllAnimations];
if (result == RequestLoading) {
self.bgView.hidden = YES;
self.imageView.hidden = YES;
self.titleLabel.hidden = YES;
[self performSelector:@selector(jz_show) withObject:nil afterDelay:1.0];
CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"opacity"];
//设置动画完成后保持原状
animation1.fillMode = kCAFillModeForwards;
anima