一,工程图。
二,代码。
RootViewController.h
#import <UIKit/UIKit.h>
//加入头文件
#import "MBProgressHUD.h" @interface RootViewController : UIViewController
<MBProgressHUDDelegate> {
MBProgressHUD *HUD;
} @end
RootViewController.m
#import "RootViewController.h"
//加入头文件
#import <unistd.h> @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //转动3s后停止
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
HUD.delegate = self;
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
[self.navigationController.view addSubview:HUD]; }
//等待3s
- (void)myTask {
sleep(3);
}