IOS之动画加载的实现过程
来源:爱站网时间:2020-06-30编辑:网友分享
随着移动的互联普及到每个人的生活中,大家对动画效果的要求也越来越高,我们程序员也在不断的为大家带来不同的展现,今天是爱站技术频道小编为大家带来的IOS之动画加载的实现过程,让我们带大家一起来学习吧!
随着移动的互联普及到每个人的生活中,大家对动画效果的要求也越来越高,我们程序员也在不断的为大家带来不同的展现,今天是爱站技术频道小编为大家带来的IOS之动画加载的实现过程,让我们带大家一起来学习吧!
首先来看看效果图
实现过程如下
控制器调用就一句代码:
[self showLoadingInView:self.view];
方便控制器如此调用,就要为控制器添加一个分类
.h文件
#import#import "GQCircleLoadView.h" @interface UIViewController (GQCircleLoad) //显示动画 - (void)showLoadingInView:(UIView*)view; //隐藏动画 - (void)hideLoad; @property (nonatomic,strong) GQCircleLoadView *loadingView; @end
.m文件
#import "UIViewController+GQCircleLoad.h" #import@implementation UIViewController (GQCircleLoad) - (GQCircleLoadView*)loadingView { return objc_getAssociatedObject(self, @"loadingView"); } - (void)setLoadingView:(GQCircleLoadView*)loadingView { objc_setAssociatedObject(self, @"loadingView", loadingView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } - (void)showLoadingInView:(UIView*)view{ if (self.loadingView == nil) { self.loadingView = [[GQCircleLoadView alloc]init]; } if (view) { [view addSubview:self.loadingView]; self.loadingView.frame = view.bounds; }else{ UIWindow *appKeyWindow = [UIApplication sharedApplication].keyWindow; [appKeyWindow addSubview:self.loadingView]; self.loadingView.frame = appKeyWindow.bounds; } } - (void)hideLoad{ [self.loadingView removeFromSuperview]; } @end
接下来就是GQCircleLoadView
继承UIView
,里面通过drawRect
画出圆圈,并且动画的实现
#import "GQCircleLoadView.h" #define WINDOW_width [[UIScreen mainScreen] bounds].size.width #define WINDOW_height [[UIScreen mainScreen] bounds].size.height static NSInteger circleCount = 3; static CGFloat cornerRadius = 10; static CGFloat magin = 15; @interface GQCircleLoadView()@property (nonatomic, strong) NSMutableArray *layerArr; @end @implementation GQCircleLoadView - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { self.backgroundColor = [UIColor clearColor]; } return self; } // 画圆 - (void)drawCircles{ for (NSInteger i = 0; i =self.layerArr.count?0:(idx+1)]; [self performSelector:@selector(drawAnimation:) withObject:nextlayer afterDelay:0.25]; *stop = YES; } }]; } } - (void)drawRect:(CGRect)rect{ [super drawRect:rect]; [self drawCircles]; } - (NSMutableArray *)layerArr{ if (_layerArr == nil) { _layerArr = [[NSMutableArray alloc] init]; } return _layerArr; } @end
Demo就不上传了,总共四个文件代码已经全贴上了!
以上就是爱站技术频道小编为大家带来的 IOS之动画加载的实现过程,大家可以按照上述的代码进行修改,说不定会给项目带来不一样的效果。
下一篇:iOS开发中集成微信支付的流程