In the open source China iOS client also used the Mbprogresshud this special effect, the main role for the application to show a transition role, commonly used to open a networked page loading process, to prevent the phenomenon of suspended animation, if the speed of slow to tell the user has been very hard to load.
On GitHub: Https://github.com/jdg/MBProgressHUD
The source code also comes with a demo, display 13 animation effect, you can choose the special effects to use as needed, the use of the same method is basically the same, when using only add MBProgressHUD.h and mbprogresshud.m into the project, in the use of the file added # Import "MBProgressHUD.h"
Only one effect is used in the open source Chinese iOS client when we select a piece of information to view the details:
We are jumping to the implementation of the Code section, in the NEWSDETAIL.M Clickfavorite and Viewdidload methods
[CPP]View Plaincopy
- -(void) Clickfavorite: (ID) Sender
- {
- Uibarbuttonitem * btn = (Uibarbuttonitem *) sender;
- BOOL isfav = [btn.title isequaltostring:@"Bookmark this article"];
- Mbprogresshud *hud = [[Mbprogresshud alloc] initWithView:self.view];
- [Tool showhud:isfav? @"Adding Favorites": @"Deleting favorites" AndView:self.view Andhud:hud];
- [[Afoscclient sharedclient]getpath:isfav? api_favorite_add:api_favorite_delete
- Parameters:[nsdictionary Dictionarywithobjectsandkeys:
- [NSString stringwithformat:@"%d", [Config instance].getuid],@"UID",
- [NSString stringwithformat:@"%d", newsid],@"ObjID",
- @"4", @"type", Nil] success:^ (afhttprequestoperation *operation, id responseobject) {
- [HUD Hide:yes];
- [Tool getOSCNotice2:operation.responseString];
- Apierror *error = [Tool getApiError2:operation.responseString];
- if (Error = = nil) {
- [Tool ToastNotification:operation.responseString AndView:self.view andloading:no Andisbottom:no];
- return;
- }
- switch (error.errorcode)
- {
- Case 1:
- {
- Btnfavorite.title = isfav? @ "Cancel Collection": @"Bookmark this article";
- Self.singleNews.favorite =!self.singlenews.favorite;
- }
- Break ;
- Case 0:
- case-2:
- case-1:
- {
- [Tool toastnotification:[nsstring stringwithformat:@"Error%@", Error.errormessage] AndView:self.view andloading:no Andisbottom:no];
- }
- Break ;
- }
- } failure:^ (Afhttprequestoperation *operation, Nserror *error) {
- [HUD Hide:yes];
- [Tool toastnotification:@"Add collection Failed" AndView:self.view Andloading:no Andisbottom:no];
- }];
- }
[CPP]View Plaincopy
- -(void) Viewdidload
- {
- [Super Viewdidload];
- Self.tabBarItem.title = @"information Details";
- Self.tabBarItem.image = [UIImage imagenamed:@"detail"];
- //webview background color removal
- [Tool ClearWebViewBackground:self.webView];
- Self.singlenews = [[Singlenews alloc] init];
- Self.navigationController.title = @"information Details";
- Self.webView.delegate = self;
- [Self.webview loadhtmlstring:@"" Baseurl:nil];
- if ([Config instance].isnetworkrunning)
- {
- Mbprogresshud *hud = [[Mbprogresshud alloc] initWithView:self.view];
- [Tool showhud:@"Loading" andView:self.view Andhud:hud];
- NSString *url = [NSString stringwithformat:@"%@?id=%d", Api_news_detail, NewsID];
- [[Afoscclient sharedclient] Getpath:url parameters:nil success:^ (afhttprequestoperation *operation, id responseObject ) {
- [Tool getOSCNotice2:operation.responseString];
- [HUD Hide:yes];
- Self.singlenews = [Tool readStrNewsDetail:operation.responseString];
- if (self.singlenews = = nil) {
- [Tool toastnotification:@"load Failed" AndView:self.view Andloading:no Andisbottom:no];
- return;
- }
- [Self loadData:self.singleNews];
- //If there is a network then cache it
- if ([Config instance].isnetworkrunning)
- {
- [Tool savecache:1 andid:self.singlenews._id andString:operation.responseString];
- }
- } failure:^ (Afhttprequestoperation *operation, Nserror *error) {
- [HUD Hide:yes];
- if ([Config instance].isnetworkrunning) {
- [Tool toastnotification:@"error network no connection" AndView:self.view Andloading:no Andisbottom:no];
- }
- }];
- }
- Else
- {
- NSString *value = [Tool getcache:1 andid:newsid];
- if (value) {
- Self.singlenews = [Tool readstrnewsdetail:value];
- [Self loadData:self.singleNews];
- }
- else {
- [Tool toastnotification:@"error network no connection" AndView:self.view Andloading:no Andisbottom:no];
- }
- }
- }
Analyze the Viewdidload method,
The first is to determine if the network is connected, if it is
Defines a Mbprogresshud object to be initialized in the current view.
[toolShowhud:@ " loading " Andview:self.viewAndhud:HUD]; is a package in the Tool class, Setting display information for Mbprogresshud
[CPP]View Plaincopy
- + (void) Showhud: (nsstring *) text andview: (uiview *) View andhud: (mbprogresshud *) hud
- {
-     [VIEW ADDSUBVIEW:HUD];  
- hud.labelText = text; //display prompt
- hud.dimbackground = yes; //make the background black and gray, Mbprogresshud Cheng Gaoliang display
- hud.square = YES; //set the height and width of the display box as
-     [HUD SHOW:YES];  
- }
Then use the getPath:parameters:success:failure: Method of the Afnetwork class library to determine whether the requested URL was successful in the block block and execute the [Tool getoscnotice2:o Peration.responsestring]; This method is also encapsulated in the tool class, encapsulated by the Tbxml parser, if the parse succeeds immediately set Mbprogresshud hidden properties [HUD Hide:yes]; If the requested URL is not successfully set directly Mbprogresshud hidden property [HUD Hide:yes], then use Gcdiscreetnotificationview to notify "error network no connection";
iOS mbprogresshud effects Learning