一,工程圖。 二,代碼。 RootViewController.h #import <UIKit/UIKit.h> //加入頭文件 #import "MBProgressHUD.h" @interface RootViewController : UIViewController <MBProgre ...
一,工程圖。
二,代碼。
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);
}