The mbprogresshud special effect is also used in the open-source Chinese IOS client. It is mainly used to display a transitional role for applications. It is often used to open a networked page loading process to prevent false positives, if the network speed is slow, it indicates that the user is loading very hard.
On GitHub: https://github.com/jdg/MBProgressHUD
The source code also comes with a demo that shows the animation effect in 13. You can select the special effect as needed. The usage is basically the same. Only mbprogresshud is added when used. H and mbprogresshud. M is dragged into the project, and the # import "mbprogresshud. h"
Only one special effect is used in the open-source Chinese IOS client. When we select a piece of information to View Details:
In the Code Section to jump to the implementation, in the clickfavorite and viewdidload methods of newsdetail. m
-(Void) clickfavorite :( ID) sender {uibarbuttonitem * BTN = (uibarbuttonitem *) sender; bool isfav = [BTN. title isequaltostring: @ "add to Favorites"]; mbprogresshud * HUD = [[mbprogresshud alloc] initwithview: Self. view]; [Tool showhud: isfav? @ "Adding to Favorites": @ "deleting from 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: O Peration. responsestring]; If (error = nil) {[Tool toastnotification: operation. responsestring andview: Self. view andloading: No andisbottom: No]; return;} switch (error. errorcode) {Case 1: {btnfavorite. title = isfav? @ "Remove from favorites": @ "add to Favorites"; 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: @ "failed to add to Favorites" andview: Self. view andloading: No andisbottom: No];}
-(Void) viewdidload {[Super viewdidload]; self. tabbaritem. title = @ ""; self. tabbaritem. image = [uiimage imagenamed: @ "detail"]; // remove the background color of webview [Tool clearwebviewbackground: Self. webview]; self. singlenews = [[singlenews alloc] init]; self. navigationcontroller. title = @ ""; self. webview. delegate = self; [self. webview loadhtmlstring: @ "" baseurl: Nil]; If ([config instance]. isnetworkrunning) {MB Progresshud * HUD = [[mbprogresshud alloc] initwithview: Self. view]; [Tool showhud: @ "loading" andview: Self. view andhud: HUD]; nsstring * url = [nsstring stringwithformat: @ "% @? Id = % d ", Token, 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: @ "loading failed" andview: Self. view andloading: No andisbottom: No]; return;} [self loaddata: Self. singlenews]; // if there is a network, 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 not connected" 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: @ "the error network is not connected" andview: Self. view andloading: No andisbottom: No] ;}}
Analyze the viewdidload method,
First, determine whether the network is connected.
Defines an mbprogresshud object in the current view for initialization.
[Toolshowhud: @ "loading" andview: Self. viewandhud: HUD]; is an encapsulation in the tool class. It sets the display information of mbprogresshud.
+ (Void) showhud :( nsstring *) text andview :( uiview *) view andhud :( mbprogresshud *) HUD {[view addsubview: HUD]; HUD. labeltext = text; // The HUD prompt is displayed. dimbackground = yes; // make the background black and gray, and make mbprogresshud highlighted. square = yes; // set the height and width of the display box to the same [HUD show: Yes];}
Then, when the afnetwork class library is usedGetpath: parameters: Success: Failure: Method, Nested in the block to determine whether the requested URL is successful. Run the [Tool getoscnotice2: operation. responsestring]; this method is also encapsulated in the tool class, which encapsulates the tbxml parser. If the parsing is successful, immediately set the mbprogresshud hidden attribute [HUD
Hide: Yes]; if the requested URL is not successful, directly set mbprogresshud to hide the attribute [HUD hide: Yes], and then use gcdiscreetnotificationview to notify "no connection to the error network ";