一、网上下载  MBProgessHUD 类文件,直接导入到工程即可

二、示例分析

在我的工程中示例如下:

1)在ShowImageViewController.h头文件代码如下:

#import <UIKit/UIKit.h>

#import "MBProgressHUD.h"

@interface ShowImageViewController : UIViewController<MBProgressHUDDelegate> {

NSString        *_picUrlString;

UIImageView     *_imageView;

MBProgressHUD    *_progressHUD;

}

@property (nonatomic, copy) NSString       *picUrlString;

@property (nonatomic, retain) IBOutlet UIImageView *imageView;

@property (nonatomic, retain) MBProgressHUD    *progressHUD;

//请求图片资源

-(void)imageResourceRequest;

//显示图片信息

-(void)displayImage:(UIImage *)image;

- (IBAction)dismissModealView:(id)sender;

-(void)removeModalView;

@end

2)在ShowImageViewController.m实现文件代码如下:

#import "ShowImageViewController.h"

#import <QuartzCore/QuartzCore.h>

@implementation ShowImageViewController

@synthesize picUrlString = _picUrlString;

@synthesize imageView = _imageView;

@synthesize progressHUD = _progressHUD;

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

self.view.backgroundColor = [UIColor grayColor];

self.view.alpha = 0.8;

//设置图片为圆角

self.imageView.backgroundColor = [UIColor clearColor];

self.imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;

self.imageView.layer.borderWidth = 5.0;

self.imageView.layer.masksToBounds = YES;

self.imageView.layer.cornerRadius = 10.0;

}

-(void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

//当进入视图时,重新设置imageView

[self.imageView setImage:nil];

[self.imageView setFrame:CGRectMake(160, 200, 0, 0)];

//显示加载等待框

self.progressHUD = [[MBProgressHUD alloc] initWithView:self.view];

[self.view addSubview:self.progressHUD];

[self.view bringSubviewToFront:self.progressHUD];

self.progressHUD.delegate = self;

self.progressHUD.labelText = @"加载中...";

[self.progressHUD show:YES];

//开启线程,请求图片资源

[NSThread detachNewThreadSelector:@selector(imageResourceRequest) toTarget:self withObject:nil];

}

//请求图片资源

-(void)imageResourceRequest

{

NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];

//根据网络数据,获得到image资源

NSData  *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:self.picUrlString]];

UIImage *image = [[UIImage alloc] initWithData:data];

[data release];

//回到主线程,显示图片信息

[self performSelectorOnMainThread:@selector(displayImage:) withObject:image waitUntilDone:NO];

[image release];

[pool release];

}

//显示图片信息

-(void)displayImage:(UIImage *)image

{

//若self.progressHUD为真,则将self.progressHUD移除,设为nil

if (self.progressHUD){

[self.progressHUD removeFromSuperview];

[self.progressHUD release];

self.progressHUD = nil;

}

//图片慢慢放大动画效果

[self.imageView setImage:image];

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.5];

[self.imageView setFrame:CGRectMake(40, 100, 240, 160)];

[UIView commitAnimations];

}

- (void)viewDidUnload

{

[self setImageView:nil];

[super viewDidUnload];

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

// Return YES for supported orientations

return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

- (IBAction)dismissModealView:(id)sender {

//设置定时器,当动画结束时,子视图从父视图中移除

[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(removeModalView) userInfo:nil repeats:NO];

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.5];

[self.imageView setFrame:CGRectMake(160, 200, 0, 0)];

[UIView commitAnimations];

}

-(void)removeModalView

{

[self.view removeFromSuperview];

}

#pragma mark -

#pragma mark MBProgressHUDDelegate methods

- (void)hudWasHidden:(MBProgressHUD *)hud {

NSLog(@"Hud: %@", hud);

// Remove HUD from screen when the HUD was hidded

[self.progressHUD removeFromSuperview];

[self.progressHUD release];

self.progressHUD = nil;

}

- (void)dealloc

{

[_picUrlString release];

[_imageView release];

[super dealloc];

}

@end

三、效果展示

四、总结

利用MBProgressHUD实现加载等待框,视觉效果大大提高

转载于:https://www.cnblogs.com/mingjieLove00/p/5493376.html

自定义加载等待框(MBProgressHUD)相关推荐

  1. IOS开发UI篇之──自定义加载等待框(MBProgressHUD)

    这里介绍一下网友开源的MBProgressHUD类,实现等待框, 一.网上下载  MBProgessHUD 类文件,直接导入到工程即可 二.示例分析 在我的工程中示例如下: 1)在ShowImageV ...

  2. QT 自定义加载等待(Loading)提示框

    QT自定义加载等待提示框 一.效果展示 二.源代码 #ifndef LOADINGDIALOG_H #define LOADINGDIALOG_H #include <QMovie> #i ...

  3. ios 自定义加载动画效果

    在开发过程中,可能会遇到各种不同的场景需要等待加载成功后才能显示数据.以下是自定义的一个动画加载view效果.      在UIViewController的中加载等到效果,如下 - (void)vi ...

  4. 页面加载时让其显示笼罩层与加载等待图片

    页面加载时让其显示笼罩层与加载等待图片(结局比较完美,过程很坎坷,所以一定总结整理下,备用): 用了ajax异步,是因为js内容不能即时的显示出来,因为js是单线程,要把队列中的任务执行完后才会执行刚 ...

  5. 微信小程序图标不支持html,微信小程序实现自定义加载图标功能

    效果图 实现思路 1.首先通过HTML+CSS实现加载动画的静态效果: 2.根据需求给每个动画设计不同的动画效果. 例如第一个加载图标的静态绘制 1.首先确定动画的盒子宽高: 2.设置盒子中每一个长方 ...

  6. WPF 加载等待动画

    WPF 加载等待动画 原文:WPF 加载等待动画 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_29844879/article/detail ...

  7. java中的类加载器有,Java自定义的类加载器,java自定义加载,在java中类加载器有以...

    Java自定义的类加载器,java自定义加载,在java中类加载器有以 在java中类加载器有以下几种java虚拟机自带的加载器 1)根类加载器(Bootstrap,c++实现)2)扩展类加载器(Ex ...

  8. android刷新时的圆形动画_Android自定义加载圈动画效果

    本文实例为大家分享了Android自定义加载圈动画展示的具体代码,供大家参考,具体内容如下 实现如下效果: 该效果图主要有3个动画: 1.旋转动画 2.聚合动画 3.扩散动画 以上3个动画都是通过Va ...

  9. asp.net读取用户控件,自定义加载用户控件

    1.自定义加载用户控件 ceshi.aspx页面 <html><body> <div id="divControls" runat="ser ...

最新文章

  1. 把一个ListT的数据复制至另一个ListT
  2. CentOs中怎样打开默认网卡并查看ip
  3. DSP、ARM和单片机的区别
  4. html中怎么用js把表格清空_一款简洁非常好用的前端表格组件库
  5. python图形化界面开发工具_图形用户界面(GUI)常见问题
  6. Windows安装Redis(转!)
  7. (33)Gulp构建脚本文件
  8. mac使用codelite运行程序没有输出
  9. Python pip的使用
  10. Java进阶: springmvc已经引入jar包仍报错lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
  11. 【Qt】arm-none-eabi-gdb-py.exe由于找不到python27.dll 无法继续执行代码
  12. Cplex求解线性规划
  13. 双人游戏根据胜负关系匹配
  14. 20211111C++练习总结
  15. java标书_java软件项目投标技术标书.doc
  16. 编写C\Cpp程序中函数声明定义中的常见错误
  17. 通过物理地址查计算机,别人知道我查电脑的物理地址,怎么处理
  18. Spark 创建 hive表报错 ROW FORMAT DELIMITED is only compatible with 'textfile', not 'parquet'
  19. Lession11 集合和泛型(ArrayList方法、Arraylist类、ArrayList添加对象、ArrayList长度、HashTable类、Hashtable类练习-----)
  20. lap 加MySQL主从复制_LAP+mysql-主从+redis

热门文章

  1. Nginx 多域名多网站绑定及禁止IP访问
  2. Docker图形界面
  3. 医疗护理与监测 智能可穿戴发展的另一个方向
  4. 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件
  5. CocoaPods集成ShareSDK
  6. 2748: [HAOI2012]音量调节
  7. 前端开发神器:grunt快速入门
  8. A.457 - Linear Cellular Automata
  9. vim文本编辑器的使用
  10. PetShop之表示层设计