首先看一下效果图:

下面贴上代码:

控制器ViewController:

#import <UIKit/UIKit.h> 
@interface ViewController : UIViewController 
@end 
/*** ---------------分割线--------------- ***/ 
#import "ViewController.h" 
#import "HWWaveView.h" 
#import "HWCircleView.h" 
#import "HWProgressView.h" 
#import "HWInstallView.h" 
@interface ViewController () 
@property (nonatomic, strong) NSTimer *timer; 
@property (nonatomic, weak) HWWaveView *waveView; 
@property (nonatomic, weak) HWCircleView *circleView; 
@property (nonatomic, weak) HWProgressView *progressView; 
@property (nonatomic, weak) HWInstallView *installView; 
@end 
@implementation ViewController 
- (void)viewDidLoad { 
 [super viewDidLoad]; 
 //创建控件 
 [self creatControl]; 
 //添加定时器 
 [self addTimer]; 
} 
- (void)creatControl 
{ 
 //波浪 
 HWWaveView *waveView = [[HWWaveView alloc] initWithFrame:CGRectMake(30, 100, 150, 150)]; 
 [self.view addSubview:waveView]; 
 self.waveView = waveView; 
 //圆圈 
 HWCircleView *circleView = [[HWCircleView alloc] initWithFrame:CGRectMake(220, 100, 150, 150)]; 
 [self.view addSubview:circleView]; 
 self.circleView = circleView; 
 //进度条 
 HWProgressView *progressView = [[HWProgressView alloc] initWithFrame:CGRectMake(30, 365, 150, 20)]; 
 [self.view addSubview:progressView]; 
 self.progressView = progressView; 
 //加载安装效果 
 HWInstallView *installView = [[HWInstallView alloc] initWithFrame:CGRectMake(220, 300, 150, 150)]; 
 [self.view addSubview:installView]; 
 self.installView = installView; 
} 
- (void)addTimer 
{ 
 _timer = [NSTimer scheduledTimerWithTimeInterval:0.2f target:self selector:@selector(timerAction) userInfo:nil repeats:YES]; 
 [[NSRunLoop mainRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes]; 
} 
- (void)timerAction 
{ 
 _waveView.progress  = 0.01; 
 _circleView.progress  = 0.01; 
 _progressView.progress  = 0.01; 
 _installView.progress  = 0.01; 
 if (_waveView.progress >= 1) { 
  [self removeTimer]; 
  NSLog(@"完成"); 
 } 
} 
- (void)removeTimer 
{ 
 [_timer invalidate]; 
 _timer = nil; 
} 
@end 
波浪HWWaveView:
[objc] view plain copy 在CODE上查看代码片派生到我的代码片
#import <UIKit/UIKit.h> 
@interface HWWaveView : UIView 
@property (nonatomic, assign) CGFloat progress; 
@end 
/*** ---------------分割线--------------- ***/ 
#import "HWWaveView.h" 
#define KHWWaveFillColor [UIColor groupTableViewBackgroundColor] //填充颜色 
#define KHWWaveTopColor [UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1.0f] //前面波浪颜色 
#define KHWWaveBottomColor [UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:0.4f] //后面波浪颜色 
@interface HWWaveView () 
@property (nonatomic, strong) CADisplayLink *displayLink; 
@property (nonatomic, assign) CGFloat wave_amplitude;//振幅a(y = asin(wx φ)   k) 
@property (nonatomic, assign) CGFloat wave_cycle;//周期w 
@property (nonatomic, assign) CGFloat wave_h_distance;//两个波水平之间偏移 
@property (nonatomic, assign) CGFloat wave_v_distance;//两个波竖直之间偏移 
@property (nonatomic, assign) CGFloat wave_scale;//水波速率 
@property (nonatomic, assign) CGFloat wave_offsety;//波峰所在位置的y坐标 
@property (nonatomic, assign) CGFloat wave_move_width;//移动的距离,配合速率设置 
@property (nonatomic, assign) CGFloat wave_offsetx;//偏移 
@property (nonatomic, assign) CGFloat offsety_scale;//上升的速度 
@end 
@implementation HWWaveView 
- (instancetype)initWithFrame:(CGRect)frame 
{ 
 if (self = [super initWithFrame:frame]) { 
  self.backgroundColor = [UIColor clearColor]; 
  //初始化信息 
  [self initInfo]; 
 } 
 return self; 
} 
- (void)initInfo 
{ 
 //进度 
 _progress = 0; 
 //振幅 
 _wave_amplitude = self.frame.size.height / 25; 
 //周期 
 _wave_cycle = 22 * M_PI / (self.frame.size.width * 0.9); 
 //两个波水平之间偏移 
 _wave_h_distance = 22 * M_PI / _wave_cycle * 0.6; 
 //两个波竖直之间偏移 
 _wave_v_distance = _wave_amplitude * 0.4; 
 //移动的距离,配合速率设置 
 _wave_move_width = 0.5; 
 //水波速率 
 _wave_scale = 0.4; 
 //上升的速度 
 _offsety_scale = 0.1; 
 //波峰所在位置的y坐标,刚开始的时候_wave_offsety是最大值 
 _wave_offsety = (1 - _progress) * (self.frame.size.height   22 * _wave_amplitude); 
 [self addDisplayLinkAction]; 
} 
- (void)addDisplayLinkAction 
{ 
 _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkAction)]; 
 [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; 
} 
- (void)displayLinkAction 
{ 
 _wave_offsetx  = _wave_move_width * _wave_scale; 
 //完成 
 if (_wave_offsety <= 0.01) [self removeDisplayLinkAction]; 
 [self setNeedsDisplay]; 
} 
- (void)removeDisplayLinkAction 
{ 
 [_displayLink invalidate]; 
 _displayLink = nil; 
} 
- (void)drawRect:(CGRect)rect 
{ 
 UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:rect]; 
 [KHWWaveFillColor setFill]; 
 [path fill]; 
 [path addClip]; 
 //绘制两个波形图 
 [self drawWaveColor:KHWWaveTopColor offsetx:0 offsety:0]; 
 [self drawWaveColor:KHWWaveBottomColor offsetx:_wave_h_distance offsety:_wave_v_distance]; 
} 
- (void)drawWaveColor:(UIColor *)color offsetx:(CGFloat)offsetx offsety:(CGFloat)offsety 
{ 
 //波浪动画,进度的实际操作范围是,多加上两个振幅的高度,到达设置进度的位置y 
 CGFloat end_offY = (1 - _progress) * (self.frame.size.height   22 * _wave_amplitude); 
 if (_wave_offsety != end_offY) { 
  if (end_offY < _wave_offsety) { 
   _wave_offsety = MAX(_wave_offsety -= (_wave_offsety - end_offY) * _offsety_scale, end_offY); 
  }else { 
   _wave_offsety = MIN(_wave_offsety  = (end_offY - _wave_offsety) * _offsety_scale, end_offY); 
  } 
 } 
 UIBezierPath *wavePath = [UIBezierPath bezierPath]; 
 for (float next_x = 0.f; next_x <= self.frame.size.width; next_x   ) { 
  //正弦函数,绘制波形 
  CGFloat next_y = _wave_amplitude * sin(_wave_cycle * next_x   _wave_offsetx   offsetx / self.bounds.size.width * 22 * M_PI)   _wave_offsety   offsety; 
  if (next_x == 0) { 
   [wavePath moveToPoint:CGPointMake(next_x, next_y - _wave_amplitude)]; 
  }else { 
   [wavePath addLineToPoint:CGPointMake(next_x, next_y - _wave_amplitude)]; 
  } 
 } 
 [wavePath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)]; 
 [wavePath addLineToPoint:CGPointMake(0, self.bounds.size.height)]; 
 [color set]; 
 [wavePath fill]; 
} 
@end 
圆圈HWCircleView:
[objc] view plain copy 在CODE上查看代码片派生到我的代码片
#import <UIKit/UIKit.h> 
@interface HWCircleView : UIView 
@property (nonatomic, assign) CGFloat progress; 
@end 
/*** ---------------分割线--------------- ***/ 
#import "HWCircleView.h" 
#define KHWCircleLineWidth 10.0f 
#define KHWCircleFont [UIFont boldSystemFontOfSize:26.0f] 
#define KHWCircleColor [UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1] 
@interface HWCircleView () 
@property (nonatomic, weak) UILabel *cLabel; 
@end 
@implementation HWCircleView 
- (instancetype)initWithFrame:(CGRect)frame 
{ 
 if (self = [super initWithFrame:frame]) { 
  self.backgroundColor = [UIColor clearColor]; 
  //百分比标签 
  UILabel *cLabel = [[UILabel alloc] initWithFrame:self.bounds]; 
  cLabel.font = KHWCircleFont; 
  cLabel.textColor = KHWCircleColor; 
  cLabel.textAlignment = NSTextAlignmentCenter; 
  [self addSubview:cLabel]; 
  self.cLabel = cLabel; 
 } 
 return self; 
} 
- (void)setProgress:(CGFloat)progress 
{ 
 _progress = progress; 
 _cLabel.text = [NSString stringWithFormat:@"%d%%", (int)floor(progress * 100)]; 
 [self setNeedsDisplay]; 
} 
- (void)drawRect:(CGRect)rect 
{ 
 //路径 
 UIBezierPath *path = [[UIBezierPath alloc] init]; 
 //线宽 
 path.lineWidth = KHWCircleLineWidth; 
 //颜色 
 [KHWCircleColor set]; 
 //拐角 
 path.lineCapStyle = kCGLineCapRound; 
 path.lineJoinStyle = kCGLineJoinRound; 
 //半径 
 CGFloat radius = (MIN(rect.size.width, rect.size.height) - KHWCircleLineWidth) * 0.5; 
 //画弧(参数:中心、半径、起始角度(3点钟方向为0)、结束角度、是否顺时针) 
 [path addArcWithCenter:(CGPoint){rect.size.width * 0.5, rect.size.height * 0.5} radius:radius startAngle:M_PI * 1.5 endAngle:M_PI * 1.5   M_PI * 22 * _progress clockwise:YES]; 
 //连线 
 [path stroke]; 
} 
@end 
进度条HWProgressView:
[objc] view plain copy 在CODE上查看代码片派生到我的代码片
#import <UIKit/UIKit.h> 
@interface HWProgressView : UIView 
@property (nonatomic, assign) CGFloat progress; 
@end 
/*** ---------------分割线--------------- ***/ 
#import "HWProgressView.h" 
#define KProgressBorderWidth 2.0f 
#define KProgressPadding 1.0f 
#define KProgressColor [UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1] 
@interface HWProgressView () 
@property (nonatomic, weak) UIView *tView; 
@end 
@implementation HWProgressView 
- (instancetype)initWithFrame:(CGRect)frame 
{ 
 if (self = [super initWithFrame:frame]) { 
  //边框 
  UIView *borderView = [[UIView alloc] initWithFrame:self.bounds]; 
  borderView.layer.cornerRadius = self.bounds.size.height * 0.5; 
  borderView.layer.masksToBounds = YES; 
  borderView.backgroundColor = [UIColor whiteColor]; 
  borderView.layer.borderColor = [KProgressColor CGColor]; 
  borderView.layer.borderWidth = KProgressBorderWidth; 
  [self addSubview:borderView]; 
  //进度 
  UIView *tView = [[UIView alloc] init]; 
  tView.backgroundColor = KProgressColor; 
  tView.layer.cornerRadius = (self.bounds.size.height - (KProgressBorderWidth   KProgressPadding) * 2) * 0.5; 
  tView.layer.masksToBounds = YES; 
  [self addSubview:tView]; 
  self.tView = tView; 
 } 
 return self; 
} 
- (void)setProgress:(CGFloat)progress 
{ 
 _progress = progress; 
 CGFloat margin = KProgressBorderWidth   KProgressPadding; 
 CGFloat maxWidth = self.bounds.size.width - margin * 2; 
 CGFloat heigth = self.bounds.size.height - margin * 2; 
 _tView.frame = CGRectMake(margin, margin, maxWidth * progress, heigth); 
} 
@end 
加载安装效果HWInstallView:
[objc] view plain copy 在CODE上查看代码片派生到我的代码片
#import <UIKit/UIKit.h> 
@interface HWInstallView : UIView 
@property (nonatomic, assign) CGFloat progress; 
@end 
/*** ---------------分割线--------------- ***/ 
#import "HWInstallView.h" 
#define KHWInstallViewMargin 10 
#define KHWInstallColor [UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1] 
@implementation HWInstallView 
- (instancetype)initWithFrame:(CGRect)frame 
{ 
 if (self = [super initWithFrame:frame]) { 
  self.backgroundColor = [UIColor clearColor]; 
 } 
 return self; 
} 
- (void)setProgress:(CGFloat)progress 
{ 
 _progress = progress; 
 [self setNeedsDisplay]; 
} 
- (void)drawRect:(CGRect)rect 
{ 
 CGContextRef context = UIGraphicsGetCurrentContext(); 
 CGFloat xCenter = rect.size.width * 0.5; 
 CGFloat yCenter = rect.size.height * 0.5; 
 CGFloat radius = MIN(rect.size.width, rect.size.height) * 0.5 - KHWInstallViewMargin; 
 //背景遮罩 
 [KHWInstallColor set]; 
 CGFloat lineW = MAX(rect.size.width, rect.size.height) * 0.5; 
 CGContextSetLineWidth(context, lineW); 
 CGContextAddArc(context, xCenter, yCenter, radius   lineW * 0.5   5, 0, M_PI * 2, 1); 
 CGContextStrokePath(context); 
 //进程圆 
 CGContextSetLineWidth(context, 1); 
 CGContextMoveToPoint(context, xCenter, yCenter); 
 CGContextAddLineToPoint(context, xCenter, 0); 
 CGFloat endAngle = - M_PI * 0.5   _progress * M_PI * 2   0.001; 
 CGContextAddArc(context, xCenter, yCenter, radius, - M_PI * 0.5, endAngle, 1); 
 CGContextFillPath(context); 
} 
@end 

以上所述是小编给大家介绍的iOS 进度条、加载、安装动画的简单实现,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对Devmax网站的支持!

iOS 进度条、加载、安装动画的简单实现的更多相关文章

  1. HTML5在微信内置浏览器下右上角菜单的调整字体导致页面显示错乱的问题

    HTML5在微信内置浏览器下,在右上角菜单的调整字体导致页面显示错乱的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

  2. iOS实现拖拽View跟随手指浮动效果

    这篇文章主要为大家详细介绍了iOS实现拖拽View跟随手指浮动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  3. ios – containerURLForSecurityApplicationGroupIdentifier:在iPhone和Watch模拟器上给出不同的结果

    我使用默认的XCode模板创建了一个WatchKit应用程序.我向iOSTarget,WatchkitAppTarget和WatchkitAppExtensionTarget添加了应用程序组权利.(这是应用程序组名称:group.com.lombax.fiveminutes)然后,我尝试使用iOSApp和WatchKitExtension访问共享文件夹URL:延期:iOS应用:但是,测试NSURL

  4. ios – Testflight无法安装应用程序

    我有几个测试人员注册了testflight并连接了他们的设备……他们有不同的ios型号……但是所有这些都有同样的问题.当他们从“safari”或“testflight”应用程序本身单击应用程序的安装按钮时……达到约90%并出现错误消息…

  5. ibm-mobilefirst – 在iOS 7.1上获取“无法安装应用程序,因为证书无效”错误

    当我的客户端将他们的设备更新到iOS7.1,然后尝试从AppCenter更新我们的应用程序时,我收到了上述错误.经过一番搜索,我找到了一个类似问题的帖子here.但是后来因为我在客户端使用AppCenter更新应用程序的环境中,我无法使用USB插件并为他们安装应用程序.在发布支持之前,是否有通过AppCenter进行下载的解决方法?

  6. ios – 视图的简单拖放?

    我正在学习iOS,但我找不到如何向UIView添加拖放行为.我试过了:它说“UIView没有可见的接口声明选择器addTarget”此外,我尝试添加平移手势识别器,但不确定这是否是我需要的它被称为,但不知道如何获得事件的坐标.在iOS中注册移动事件回调/拖放操作的标准简单方法是什么?

  7. ios – 什么控制iTunes中iPhone应用程序支持的语言列表?

    什么控制iPhone应用程序的iTunes页面中支持的语言?

  8. ios – 获得APNs响应BadDeviceToken或Unregistered的可能原因是什么?

    我知道设备令牌在某些时候是有效的.用户如何使其设备令牌变坏?从关于“未注册”的文档:Thedevicetokenisinactiveforthespecifiedtopic.这是否意味着应用程序已被删除?.您应该看到四种分发方法:如果您选择AppStore或Enterprise,您将在后面的对话框中看到Xcode将APNS权利更改为生产:如果选择AdHoc或Development,则aps-environment下的文本将是开发,然后应与后端的配置匹配.

  9. ios – 当我关闭应用程序时,我从调试器获得消息:由于信号15而终止

    我怎么能解决这个问题,我不知道这个链接MypreviousproblemaboutCoredata对我的问题有影响吗?当我cmd应用程序的Q时,将出现此消息.Messagefromdebugger:Terminatedduetosignal15如果谁知道我以前的问题的解决方案,请告诉我.解决方法>来自调试器的消息:每当用户通过CMD-Q(退出)或STOP手动终止应用程序(无论是在iOS模拟器中还是

  10. ios – NSUbiquityIdentityDidChangeNotification和SIGKILL

    当应用程序被发送到后台时,我们会删除观察者吗?我遇到的问题是,当UbiquityToken发生变化时,应用程序终止,因为用户已经更改了iCloud设置.你们如何设法订阅这个通知,如果你不这样做,你会做什么来跟踪当前登录的iCloud用户?

随机推荐

  1. iOS实现拖拽View跟随手指浮动效果

    这篇文章主要为大家详细介绍了iOS实现拖拽View跟随手指浮动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  2. iOS – genstrings:无法连接到输出目录en.lproj

    使用我桌面上的项目文件夹,我启动终端输入:cd然后将我的项目文件夹拖到终端,它给了我路径.然后我将这行代码粘贴到终端中找.-name*.m|xargsgenstrings-oen.lproj我在终端中收到此错误消息:genstrings:无法连接到输出目录en.lproj它多次打印这行,然后说我的项目是一个目录的路径?没有.strings文件.对我做错了什么的想法?

  3. iOS 7 UIButtonBarItem图像没有色调

    如何确保按钮图标采用全局色调?解决方法只是想将其转换为根注释,以便为“回答”复选标记提供更好的上下文,并提供更好的格式.我能想出这个!

  4. ios – 在自定义相机层的AVFoundation中自动对焦和自动曝光

    为AVFoundation定制图层相机创建精确的自动对焦和曝光的最佳方法是什么?

  5. ios – Xcode找不到Alamofire,错误:没有这样的模块’Alamofire’

    我正在尝试按照github(https://github.com/Alamofire/Alamofire#cocoapods)指令将Alamofire包含在我的Swift项目中.我创建了一个新项目,导航到项目目录并运行此命令sudogeminstallcocoapods.然后我面临以下错误:搜索后我设法通过运行此命令安装cocoapodssudogeminstall-n/usr/local/bin

  6. ios – 在没有iPhone6s或更新的情况下测试ARKit

    我在决定下载Xcode9之前.我想玩新的框架–ARKit.我知道要用ARKit运行app我需要一个带有A9芯片或更新版本的设备.不幸的是我有一个较旧的.我的问题是已经下载了新Xcode的人.在我的情况下有可能运行ARKit应用程序吗?那个或其他任何模拟器?任何想法或我将不得不购买新设备?解决方法任何iOS11设备都可以使用ARKit,但是具有高质量AR体验的全球跟踪功能需要使用A9或更高版本处理器的设备.使用iOS11测试版更新您的设备是必要的.

  7. 将iOS应用移植到Android

    我们制作了一个具有2000个目标c类的退出大型iOS应用程序.我想知道有一个最佳实践指南将其移植到Android?此外,由于我们的应用程序大量使用UINavigation和UIView控制器,我想知道在Android上有类似的模型和实现.谢谢到目前为止,guenter解决方法老实说,我认为你正在计划的只是制作难以维护的糟糕代码.我意识到这听起来像很多工作,但从长远来看它会更容易,我只是将应用程序的概念“移植”到android并从头开始编写.

  8. ios – 在Swift中覆盖Objective C类方法

    我是Swift的初学者,我正在尝试在Swift项目中使用JSONModel.我想从JSONModel覆盖方法keyMapper,但我没有找到如何覆盖模型类中的Objective-C类方法.该方法的签名是:我怎样才能做到这一点?解决方法您可以像覆盖实例方法一样执行此操作,但使用class关键字除外:

  9. ios – 在WKWebView中获取链接URL

    我想在WKWebView中获取tapped链接的url.链接采用自定义格式,可触发应用中的某些操作.例如HTTP://我的网站/帮助#深层链接对讲.我这样使用KVO:这在第一次点击链接时效果很好.但是,如果我连续两次点击相同的链接,它将不报告链接点击.是否有解决方法来解决这个问题,以便我可以检测每个点击并获取链接?任何关于这个的指针都会很棒!解决方法像这样更改addobserver在observeValue函数中,您可以获得两个值

  10. ios – 在Swift的UIView中找到UILabel

    我正在尝试在我的UIViewControllers的超级视图中找到我的UILabels.这是我的代码:这是在Objective-C中推荐的方式,但是在Swift中我只得到UIViews和CALayer.我肯定在提供给这个方法的视图中有UILabel.我错过了什么?我的UIViewController中的调用:解决方法使用函数式编程概念可以更轻松地实现这一目标.

返回
顶部