回答
請使用MBProgressHUD。
#import <UIKit/UIKit.h>;
#import "MBProgressHUD.h" // import the .h file into project.
@class MBProgressHudDemoViewController;
@interface MBProgressHudDemoAppDelegate : NSObject <UIApplicationDelegate,MBProgressHUDDelegate> {
UIWindow *window;
MBProgressHudDemoViewController *viewController;
MBProgressHUD *HUD;// create the object of Hud.
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MBProgressHudDemoViewController *viewController;
-(void)showProgressHUD:(NSString*)msg;
-(void)hideProgressHUD;
@end
#import <UIKit/UIKit.h>
#import "MBProgressHudDemoAppDelegate.h"
@interface MBProgressHudDemoViewController : UIViewController {
MBProgressHudDemoAppDelegate *delegate;
}
@end
ViewControll.m文件
#import "MBProgressHudDemoViewController.h"
#import "MBProgressHudDemoAppDelegate.h"
@implementation MBProgressHudDemoViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(nextDetail) withObject:nil afterDelay:2];
}
-(void)nextDetail{
delegate = (MBProgressHudDemoAppDelegate*)[[UIApplication sharedApplication] delegate];
[delegate showProgressHUD:@"Please Wait..."];
[self performSelector:@selector(RemoveHud) withObject:nil afterDelay:2];
}
-(void)RemoveHud{
[delegate hideProgressHUD];
}
@end
輸出
你可以d ownload教程從here.http://bit.ly/Rc3azb – 2012-08-14 06:56:57
從https://github.com/jdg/MBProgressHUD獲取圖書館。有兩行你需要,一個打開它,另一個隱藏。在git hub上向下滾動,你會看到代碼行。 – 2013-09-26 11:43:53
,如果你想使事情變得簡單,您可以使用UIActivityIndicator。或者有很多開源活動指標,除了展示紡車之外,還有很多花哨的東西。 MBProgressHUD和SVProgressHUD是兩個很好的實現。
您可以使用內置的活動指示燈。
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width/2 , (alert.bounds.size.height) /2);
[indicator startAnimating];
只需將它作爲子視圖添加到您的視圖中即可。
創建YourViewController,然後添加的MBProgressHUB庫到您的項目(你可以從here庫);下載項目並將庫移動到您的項目中。
然後你可以用下面的代碼來實現你的任務:
YourViewController.h
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
@interface YourViewController : UITableViewController <MBProgressHUDDelegate>
{
MBProgressHUD *hud;
}
YourViewController.m
#import "YourViewController.h"
@interface YourViewController()
@end
@implementation YourViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initializeProgressLoading];
[self getObjects];
[hud hide:YES afterDelay:1];
}
-(void) initializeProgressLoading {
hud = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:hud];
hud.delegate = self;
hud.labelText = @"Loading";
[hud showWhileExecuting:@selector(sleep) onTarget:self withObject:nil animated:YES];
}
- (void)sleep {
sleep(50000);
}
- (void) getObjects {
// connect to db and get all objects
//you can write any thing here
}
- (void)hudWasHidden:(MBProgressHUD *)hud1 {
// Remove HUD from screen when the HUD was hidded
[hud removeFromSuperview];
hud = nil;
}
- 1. IOS子視圖顯示,但不加載
- 2. 如何加載和顯示動畫PNG
- 3. 如何在iOS中使用動畫顯示容器視圖?
- 4. jQuery自動完成:如何顯示動畫GIF加載圖像
- 5. 動畫顯示的視圖
- 6. iOS視圖動畫
- 7. 添加逆向動畫時,Android動畫顯示空白視圖
- 8. 如何在視圖中自動加載和顯示圖像(Codeigniter)
- 9. 動畫加載圖標不動畫jquery顯示
- 10. 如何顯示某些圖像的加載進度動畫?
- 11. Chart.js - 如何在繪製圖表之前顯示加載動畫
- 12. KendoUI圖表 - 如何在加載數據時顯示動畫?
- 13. 如何在頁面加載時顯示ajax加載gif動畫?
- 14. 如何將啓動畫面加載視圖直到其加載
- 15. 如何在Meteor 0.8中加載圖片時顯示加載動畫
- 16. iOS動畫滾動視圖
- 17. 視圖控制器的動畫加載
- 18. iOS - 如何在活動視圖仍然呈現動畫時顯示UIView?
- 19. 加載UIWebView塊滾動視圖動畫
- 20. AOS在滾動動畫加載之前顯示在視口中
- 21. IOS支持顯示GIF動畫圖像?
- 22. 如何從插件顯示視圖,通過Autofac動態加載?
- 23. 如何顯示緩慢加載助手視圖加載指標?
- 24. Xcode顯示加載視圖,直到第二個視圖加載(在segue顯示)
- 25. 在iOS 8的UISplitViewController中動畫顯示/隱藏主視圖
- 26. iOS模式視圖控制器PageCurl動畫未顯示
- 27. 動畫旋轉視圖IOS
- 28. iOS視圖'摺疊'動畫
- 29. 動畫與視圖iOS
- 30. 使用的SwingWorker顯示加載動畫
您可以簡單地使用UIActivityIndicator是你只是想顯示一個加載過程... – IronManGill 2012-08-14 06:53:11