1. 程式人生 > >自定義載入等待框(MBProgressHUD)

自定義載入等待框(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 (nonatomiccopyNSString           *picUrlString;

@property (nonatomicretainIBOutletUIImageView *imageView;

@property (nonatomicretainMBProgressHUD    *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

{

    [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(16020000)];

//顯示載入等待框

    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 = [[NSAutoreleasePoolallocinit];

//根據網路資料,獲得到image資源

    NSData  *data = http://www.cnblogs.com/snake-hand/archive/2012/08/13/[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:self.picUrlString]];

    UIImage *image = [[UIImage allocinitWithData: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(40100240160)];

    [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(16020000)];

    [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