日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/11/30 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS开发UI篇之──自定义加载等待框(MBProgressHUD) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這里介紹一下網(wǎng)友開(kāi)源的MBProgressHUD類,實(shí)現(xiàn)等待框,


一、網(wǎng)上下載 ?MBProgessHUD 類文件,直接導(dǎo)入到工程即可

二、示例分析

在我的工程中示例如下:

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;

//請(qǐng)求圖片資源

-(void)imageResourceRequest;


//顯示圖片信息

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



- (IBAction)dismissModealView:(id)sender;

-(void)removeModalView;


@end



2)在ShowImageViewController.m實(shí)現(xiàn)文件代碼如下:

#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;

?? ?

? ? //設(shè)置圖片為圓角

? ? 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];

? ? //當(dāng)進(jìn)入視圖時(shí),重新設(shè)置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];

?? ?

? ? //開(kāi)啟線程,請(qǐng)求圖片資源

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

}

//請(qǐng)求圖片資源

-(void)imageResourceRequest

{

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

? ? //根據(jù)網(wǎng)絡(luò)數(shù)據(jù),獲得到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移除,設(shè)為nil

? ? if (self.progressHUD){

? ? ? ? [self.progressHUD removeFromSuperview];

? ? ? ? [self.progressHUD release];

? ? ? ? self.progressHUD = nil;

? ? }

?? ?

? ? //圖片慢慢放大動(dòng)畫(huà)效果

? ? [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 {? ?

? ? //設(shè)置定時(shí)器,當(dāng)動(dòng)畫(huà)結(jié)束時(shí),子視圖從父視圖中移除

? ? [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


三、效果展示


四、總結(jié)

利用MBProgressHUD實(shí)現(xiàn)加載等待框,視覺(jué)效果大大提高

轉(zhuǎn)載于:https://www.cnblogs.com/snake-hand/archive/2012/08/13/2636219.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的IOS开发UI篇之──自定义加载等待框(MBProgressHUD)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。