iOS mbprogresshud effects Learning

Source: Internet
Author: User

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
  1. -(void) Clickfavorite: (ID) Sender
  2. {
  3. Uibarbuttonitem * btn = (Uibarbuttonitem *) sender;
  4. BOOL isfav = [btn.title isequaltostring:@"Bookmark this article"];
  5. Mbprogresshud *hud = [[Mbprogresshud alloc] initWithView:self.view];
  6. [Tool showhud:isfav? @"Adding Favorites": @"Deleting favorites" AndView:self.view Andhud:hud];
  7. [[Afoscclient sharedclient]getpath:isfav? api_favorite_add:api_favorite_delete
  8. Parameters:[nsdictionary Dictionarywithobjectsandkeys:
  9. [NSString stringwithformat:@"%d", [Config instance].getuid],@"UID",
  10. [NSString stringwithformat:@"%d", newsid],@"ObjID",
  11. @"4", @"type", Nil] success:^ (afhttprequestoperation *operation, id responseobject) {
  12. [HUD Hide:yes];
  13. [Tool getOSCNotice2:operation.responseString];
  14. Apierror *error = [Tool getApiError2:operation.responseString];
  15. if (Error = = nil) {
  16. [Tool ToastNotification:operation.responseString AndView:self.view andloading:no Andisbottom:no];
  17. return;
  18. }
  19. switch (error.errorcode)
  20. {
  21. Case 1:
  22. {
  23. Btnfavorite.title = isfav?  @ "Cancel Collection": @"Bookmark this article";
  24. Self.singleNews.favorite =!self.singlenews.favorite;
  25. }
  26. Break ;
  27. Case 0:
  28. case-2:
  29. case-1:
  30. {
  31. [Tool toastnotification:[nsstring stringwithformat:@"Error%@", Error.errormessage] AndView:self.view andloading:no  Andisbottom:no];
  32. }
  33. Break ;
  34. }
  35. } failure:^ (Afhttprequestoperation *operation, Nserror *error) {
  36. [HUD Hide:yes];
  37. [Tool toastnotification:@"Add collection Failed" AndView:self.view Andloading:no Andisbottom:no];
  38. }];
  39. }



[CPP]View Plaincopy
  1. -(void) Viewdidload
  2. {
  3. [Super Viewdidload];
  4. Self.tabBarItem.title = @"information Details";
  5. Self.tabBarItem.image = [UIImage imagenamed:@"detail"];
  6. //webview background color removal
  7. [Tool ClearWebViewBackground:self.webView];
  8. Self.singlenews = [[Singlenews alloc] init];
  9. Self.navigationController.title = @"information Details";
  10. Self.webView.delegate = self;
  11. [Self.webview loadhtmlstring:@"" Baseurl:nil];
  12. if ([Config instance].isnetworkrunning)
  13. {
  14. Mbprogresshud *hud = [[Mbprogresshud alloc] initWithView:self.view];
  15. [Tool showhud:@"Loading" andView:self.view Andhud:hud];
  16. NSString *url = [NSString stringwithformat:@"%@?id=%d", Api_news_detail, NewsID];
  17. [[Afoscclient sharedclient] Getpath:url parameters:nil success:^ (afhttprequestoperation *operation, id responseObject ) {
  18. [Tool getOSCNotice2:operation.responseString];
  19. [HUD Hide:yes];
  20. Self.singlenews = [Tool readStrNewsDetail:operation.responseString];
  21. if (self.singlenews = = nil) {
  22. [Tool toastnotification:@"load Failed" AndView:self.view Andloading:no Andisbottom:no];
  23. return;
  24. }
  25. [Self loadData:self.singleNews];
  26. //If there is a network then cache it
  27. if ([Config instance].isnetworkrunning)
  28. {
  29. [Tool savecache:1 andid:self.singlenews._id andString:operation.responseString];
  30. }
  31. } failure:^ (Afhttprequestoperation *operation, Nserror *error) {
  32. [HUD Hide:yes];
  33. if ([Config instance].isnetworkrunning) {
  34. [Tool toastnotification:@"error network no connection" AndView:self.view Andloading:no Andisbottom:no];
  35. }
  36. }];
  37. }
  38. Else
  39. {
  40. NSString *value = [Tool getcache:1 andid:newsid];
  41. if (value) {
  42. Self.singlenews = [Tool readstrnewsdetail:value];
  43. [Self loadData:self.singleNews];
  44. }
  45. else {
  46. [Tool toastnotification:@"error network no connection" AndView:self.view Andloading:no Andisbottom:no];
  47. }
  48. }
  49. }


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
    1. +  (void) Showhud: (nsstring *) text  andview: (uiview *) View andhud: (mbprogresshud *) hud  
    2. {   
    3.     [VIEW ADDSUBVIEW:HUD];  
    4.      hud.labelText = text; //display prompt   
    5.     hud.dimbackground = yes; //make the background black and gray, Mbprogresshud Cheng Gaoliang display   
    6.     hud.square = YES; //set the height and width of the display box as   
    7.     [HUD SHOW:YES];  
    8. }  

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.