自定義載入等待框(MBProgressHUD)
一、網上下載 MBProgessHUD 類檔案,直接匯入到工程
MBProgressHUD 下載地址是: http://github.com/matej/MBProgressHUD
二、在我的工程中示例如下:
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) IBOutletUIImageView *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
@synthesize imageView = _imageView;
@synthesize progressHUD = _progressHUD;
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view from its nib.
self.view.backgroundColor = [UIColorgrayColor];
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];
//開啟執行緒,請求圖片資源
[NSThreaddetachNewThreadSelector:@selector(imageResourceRequest) toTarget:selfwithObject:nil];
}
//請求圖片資源
-(void)imageResourceRequest
{
NSAutoreleasePool *pool = [[NSAutoreleasePoolalloc] init];
//根據網路資料,獲得到image資源
NSData *data = http://www.cnblogs.com/snake-hand/archive/2012/08/13/[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:self.picUrlString]];
UIImage *image = [[UIImage alloc] initWithData:data];
[data release];
//回到主執行緒,顯示圖片資訊
[selfperformSelectorOnMainThread:@selector(displayImage:) withObject:imagewaitUntilDone: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];
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:0.5];
[self.imageView setFrame:CGRectMake(40, 100, 240, 160)];
[UIViewcommitAnimations];
}
- (void)viewDidUnload
{
[selfsetImageView:nil];
[superviewDidUnload];
// 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 {
//設定定時器,當動畫結束時,子檢視從父檢視中移除
[NSTimerscheduledTimerWithTimeInterval:0.5target:selfselector:@selector(removeModalView) userInfo:nilrepeats:NO];
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:0.5];
[self.imageView setFrame:CGRectMake(160, 200, 0, 0)];
[UIViewcommitAnimations];
}
-(void)removeModalView
{
[self.viewremoveFromSuperview];
}
#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)
一、網上下載 MBProgessHUD 類檔案,直接匯入到工程 MBProgressHUD 下載地址是: http://github.com/matej/MBProgressHUD 二、在我的工程中示例如下: 1)在ShowImageViewController.
iOS開發之自定義載入等待框(MBProgressHUD)
原文地址:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一個開源專案,實現了很多種樣式的提示框,使用上簡單、方便,並且可以對顯示的內容進行自定義,功能很強大,很多專案中都有
前端 自定義確認提示框(二)
上一篇有自定義提示框,前端 自定義彈出框-提示框(一),這篇推薦一個確認框的實現。 JS預設確認框 確認框 var result=confirm('確認刪除XX檔案?');result為bool型別 回覆確認框 var result=prompt('請輸入檔案標題:');result返回輸入的值
android 自定義ListView實現下拉重新整理、分頁載入、點選事件——自定義控制元件學習(七)
package com.example.administrator.customerpulldownrefreshandpageload; import android.content.Context; import android.os.Handler; import android.os.Message
xgboost 自定義評價函數(metric)與目標函數
binary ret and 參數 cnblogs from valid ges zed 比賽得分公式如下: 其中,P為Precision , R為 Recall。 GBDT訓練基於驗證集評價,此時會調用評價函數,XGBoost的best_iteration和
XAF 框架中,自定義參數動作(Action),輸入參數的控件可定義,用於選擇組織及項目
示例 app frame tro href express documents 定義 ron XAF 框架中,如何生成一個自定義參數動作(Action),輸入參數的控件可定義? 參考文檔:https://documentation.devexpress.com/eXpres
AngularJs自定義指令詳解(5) - link
演示 hang cursor off drag font 雙向 事件 date 在指令中操作DOM,我們需要link參數,這參數要求聲明一個函數,稱之為鏈接函數。 寫法: link: function(scope, element, attrs) { // 在這裏操作DO
sench touch 自定義小圖標(轉)
found conf custom cmd svg logs 頁面 一個 會有 自定義圖標的方法 Sencha touch自帶圖標有限,有時需要自己添加圖標。下面介紹自定義圖標的方法: 首先需要生成圖標字體。有許多網站提供在線生成圖標字體的功能,比如IcoMoon,通過這個
vue2 自定義 折疊列表(Accordion)組件
rep link 分享圖片 toggle sset pac baseline object 列表 1.自定義 折疊列表 Accordion.vue <!-- 折疊列表 組件 --> <template> <nav :class="$st
ASP.NET MVC 學習筆記-7.自定義配置信息(後續)
字符串 return abstract 新的 work 生成 value DC 連接字符串加密 自定義配置信息的高級應用 通過上篇博文對簡單的自定義配置信息的學習,使得更加靈活的控制系統配置信息。實際項目中,這種配置的靈活度往往無法滿足項目的靈活度和擴展性。 比如,一個
vue--自定義指令進行驗證(1)
指令 borde order hone 大於 正則表達 display UNC pen 實例代碼: <template> <div id="app" class="app"> <h3>{{msg}}</h3> &
自定義AXI-IP核(轉)
目的: 自定義一個IP核,通過AXI匯流排與ARM系統連線 環境: Win7 32bit Vivado2014.4.1 Xilinx sdk2014.4 開發板: Zc702 &nbs
CSS3載入等待動畫(loading)
效果: CSS樣式表程式碼: #errmsg { color: #ff0000; text-align: center; margin: 0px auto; line-height: 30px; } #colorfulPulse { width
Unity3D 自定義編輯器介面(Inspector)
今天看一個指令碼,本想看看在 Inspector 介面的變數在腳本里的用途,然後查詢變數名的時候怎麼也找不到,自己也是驚訝。通過網上搜索才瞭解到原來 Inspector介面 是可以自己定義的。 當然自己定義,當然也需要寫一個指令碼來改的。可能是為了讓介面整潔的目的。 首先
OC中UITableView之自定義cell的使用(2):通過程式碼建立
在使用UITableView做開發時,常常會遇到 系統提供的樣式無法滿足專案需求的情況,這時就需要根據需求來自定義cell。 自定義cell有兩種方式: · 通過xib自定義cell(適用於cell中子控制元件個數固定、cell樣式統一的結構,例如:商品的列表頁面)
OC中UITableView之自定義cell的使用(1):通過xib建立
在使用UITableView做開發時,常常會遇到 系統提供的樣式無法滿足專案需求的情況,這時就需要根據需求來自定義cell。 自定義cell有兩種方式: · 通過xib自定義cell(適用於cell中子控制元件個數固定、cell樣式統一的結構,例如:商品的列表頁面)
百度地圖--獲取自定義區域JSON資料(上)
基於百度地圖的自定義區域繪圖–呼叫地圖 註冊百度地圖的SDK: 這一步是呼叫百度地圖的核心,通過獲取SDK才能進行相關操作。 使用百度地圖: 在html中引入js檔案: <script src="http://api.map.baidu.com/a
百度地圖--獲取自定義區域JSON資料(下)
基於百度地圖的自定義區域繪圖–繪製區域 基於上一篇的尊卑工作後,開始正式繪圖: 第一步:建立react專案(我的目錄結構如圖)
8、jeecg 筆記之 自定義word 模板匯出(一)
1、前言 jeecg 中已經自帶 word 的匯出匯出功能,其所使用的也是 easypoi,儘管所匯出的 word 能滿足大部分需求, 但總是有需要用到自定義 word匯出模板,下文所用到的皆是 easypoi 提供的,為方便下次翻閱,故記之。 2、程式碼部分 2.1、controll
結合案例講解MapReduce重要知識點 ----------- 自定義MapReduce資料型別(1)重寫Writable介面
重寫Writable介面 如下程式碼就是自定義mr資料型別,在wordcount類使用它。 WordCountWritable import java.io.DataInput; import java.io.DataOutput; import java.io.IOE