diff --git a/Demo/Classes/HudDemoAppDelegate.h b/Demo/Classes/HudDemoAppDelegate.h index 2e36b0c..57629b4 100644 --- a/Demo/Classes/HudDemoAppDelegate.h +++ b/Demo/Classes/HudDemoAppDelegate.h @@ -12,11 +12,11 @@ @interface HudDemoAppDelegate : NSObject { UIWindow *window; - HudDemoViewController *viewController; + UINavigationController *navController; } @property (nonatomic, retain) IBOutlet UIWindow *window; -@property (nonatomic, retain) IBOutlet HudDemoViewController *viewController; +@property (nonatomic, retain) IBOutlet UINavigationController *navController; @end diff --git a/Demo/Classes/HudDemoAppDelegate.m b/Demo/Classes/HudDemoAppDelegate.m index 50a34d4..a68acde 100644 --- a/Demo/Classes/HudDemoAppDelegate.m +++ b/Demo/Classes/HudDemoAppDelegate.m @@ -12,19 +12,19 @@ @implementation HudDemoAppDelegate @synthesize window; -@synthesize viewController; +@synthesize navController; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch - [window addSubview:viewController.view]; + [window addSubview:navController.view]; [window makeKeyAndVisible]; } - (void)dealloc { - [viewController release]; + [navController release]; [window release]; [super dealloc]; } diff --git a/Demo/Classes/HudDemoViewController.h b/Demo/Classes/HudDemoViewController.h index 85fc24c..ccb73cd 100644 --- a/Demo/Classes/HudDemoViewController.h +++ b/Demo/Classes/HudDemoViewController.h @@ -19,6 +19,7 @@ - (IBAction)showWithLabelDeterminate:(id)sender; - (IBAction)showWithCustomView:(id)sender; - (IBAction)showWithLabelMixed:(id)sender; +- (IBAction)showUsingBlocks:(id)sender; - (void)myTask; - (void)myProgressTask; diff --git a/Demo/Classes/HudDemoViewController.m b/Demo/Classes/HudDemoViewController.m index 6276db9..2283811 100644 --- a/Demo/Classes/HudDemoViewController.m +++ b/Demo/Classes/HudDemoViewController.m @@ -14,6 +14,11 @@ #pragma mark - #pragma mark Lifecycle methods +- (void)viewDidLoad { + UIView *content = [[self.view subviews] objectAtIndex:0]; + ((UIScrollView *)self.view).contentSize = content.bounds.size; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview // Release anything that's not essential, such as cached data @@ -26,6 +31,11 @@ return YES; } +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + UIView *content = [[self.view subviews] objectAtIndex:0]; + ((UIScrollView *)self.view).contentSize = content.bounds.size; +} + - (void)dealloc { [super dealloc]; } @@ -106,6 +116,10 @@ // The hud will dispable all input on the view HUD = [[MBProgressHUD alloc] initWithView:self.view]; + // The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/ + // Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators) + HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease]; + // Set custom view mode HUD.mode = MBProgressHUDModeCustomView; @@ -117,10 +131,6 @@ HUD.labelText = @"Completed"; - // The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/ - // Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators) - HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease]; - // This would only show the completed text with no visible custom view // HUD.customView = [[UIView alloc] initWithFrame:CGRectZero]; @@ -144,6 +154,25 @@ [HUD showWhileExecuting:@selector(myMixedTask) onTarget:self withObject:nil animated:YES]; } +- (IBAction)showUsingBlocks:(id)sender { + dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ + // Show the HUD in the main tread + dispatch_async(dispatch_get_main_queue(), ^{ + // No need to hod onto (retain) + MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; + hud.labelText = @"Loading"; + }); + + // Do a taks in the background + [self myTask]; + + // Hide the HUD in the main tread + dispatch_async(dispatch_get_main_queue(), ^{ + [MBProgressHUD hideHUDForView:self.view animated:YES]; + }); + }); +} + #pragma mark - #pragma mark Execution code diff --git a/Demo/Default.png b/Demo/Default.png new file mode 100644 index 0000000..1f8a979 Binary files /dev/null and b/Demo/Default.png differ diff --git a/Demo/HudDemo.xcodeproj/project.pbxproj b/Demo/HudDemo.xcodeproj/project.pbxproj index ba55088..bfb8e91 100755 --- a/Demo/HudDemo.xcodeproj/project.pbxproj +++ b/Demo/HudDemo.xcodeproj/project.pbxproj @@ -16,6 +16,9 @@ 28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; }; 28D7ACF80DDB3853001CB0EB /* HudDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* HudDemoViewController.m */; }; D22F7D810F85241C00550BB3 /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = D22F7D800F85241C00550BB3 /* MBProgressHUD.m */; }; + D277FDB311FC834200304321 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = D277FDB211FC834200304321 /* Default.png */; }; + D277FDB911FC877E00304321 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = D277FDB711FC877E00304321 /* Icon.png */; }; + D277FDBA11FC877E00304321 /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D277FDB811FC877E00304321 /* Icon@2x.png */; }; D2F88CD6115E9F7F00E6DB82 /* 37x-Checkmark.png in Resources */ = {isa = PBXBuildFile; fileRef = D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */; }; /* End PBXBuildFile section */ @@ -35,7 +38,10 @@ 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; D22F7D7F0F85241C00550BB3 /* MBProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MBProgressHUD.h; path = ../MBProgressHUD.h; sourceTree = SOURCE_ROOT; }; D22F7D800F85241C00550BB3 /* MBProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MBProgressHUD.m; path = ../../MBProgressHUD.m; sourceTree = ""; }; - D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "37x-Checkmark.png"; path = "../Images/37x-Checkmark.png"; sourceTree = ""; }; + D277FDB211FC834200304321 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; + D277FDB711FC877E00304321 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = ""; }; + D277FDB811FC877E00304321 /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon@2x.png"; sourceTree = ""; }; + D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "37x-Checkmark.png"; path = "Images/37x-Checkmark.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -61,7 +67,6 @@ 1D3623250D0F684500981E51 /* HudDemoAppDelegate.m */, 28D7ACF60DDB3853001CB0EB /* HudDemoViewController.h */, 28D7ACF70DDB3853001CB0EB /* HudDemoViewController.m */, - D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */, ); path = Classes; sourceTree = ""; @@ -98,8 +103,8 @@ 29B97317FDCFA39411CA2CEA /* Resources */ = { isa = PBXGroup; children = ( - 2899E5210DE3E06400AC0155 /* HudDemoViewController.xib */, - 28AD733E0D9D9553002E5188 /* MainWindow.xib */, + D277FDBF11FC880100304321 /* UI */, + D277FDBD11FC879500304321 /* Images */, 8D1107310486CEB800E47090 /* Info.plist */, ); name = Resources; @@ -115,6 +120,26 @@ name = Frameworks; sourceTree = ""; }; + D277FDBD11FC879500304321 /* Images */ = { + isa = PBXGroup; + children = ( + D277FDB711FC877E00304321 /* Icon.png */, + D277FDB811FC877E00304321 /* Icon@2x.png */, + D277FDB211FC834200304321 /* Default.png */, + D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */, + ); + name = Images; + sourceTree = ""; + }; + D277FDBF11FC880100304321 /* UI */ = { + isa = PBXGroup; + children = ( + 2899E5210DE3E06400AC0155 /* HudDemoViewController.xib */, + 28AD733E0D9D9553002E5188 /* MainWindow.xib */, + ); + name = UI; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -160,6 +185,9 @@ 28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */, 2899E5220DE3E06400AC0155 /* HudDemoViewController.xib in Resources */, D2F88CD6115E9F7F00E6DB82 /* 37x-Checkmark.png in Resources */, + D277FDB311FC834200304321 /* Default.png in Resources */, + D277FDB911FC877E00304321 /* Icon.png in Resources */, + D277FDBA11FC877E00304321 /* Icon@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Demo/HudDemoViewController.xib b/Demo/HudDemoViewController.xib index 53b2d29..9d24939 100644 --- a/Demo/HudDemoViewController.xib +++ b/Demo/HudDemoViewController.xib @@ -2,17 +2,17 @@ 528 - 10C540 - 740 - 1038.25 - 458.00 + 10F569 + 788 + 1038.29 + 461.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 62 + 117 YES - + YES @@ -31,164 +31,197 @@ YES IBFilesOwner + IBCocoaTouchFramework IBFirstResponder + IBCocoaTouchFramework - + 274 YES - - - 294 - {{20, 20}, {280, 40}} - - NO + + + 290 + + YES + + + 294 + {{20, 20}, {280, 40}} + + NO + NO + IBCocoaTouchFramework + 0 + 3 + + Helvetica-Bold + 15 + 16 + + 1 + Simple indeterminate progress + + 1 + MSAxIDEAA + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + 3 + MAA + + + + + 294 + {{20, 68}, {280, 40}} + + NO + NO + IBCocoaTouchFramework + 0 + 3 + + 1 + With label + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + + + + 294 + {{20, 116}, {280, 40}} + + NO + NO + IBCocoaTouchFramework + 0 + 3 + + 1 + With details label + With details label + With details label + With details label + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + + + + 294 + {{20, 164}, {280, 40}} + + NO + NO + IBCocoaTouchFramework + 0 + 3 + + 1 + Determinate mode + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + + + + 294 + {{20, 260}, {280, 40}} + + NO + NO + IBCocoaTouchFramework + 0 + 3 + + 1 + Mode switching + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + + + + 294 + {{20, 308}, {280, 40}} + + NO + NO + IBCocoaTouchFramework + 0 + 3 + + 1 + GCD and blocks + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + + + + 294 + {{20, 212}, {280, 40}} + + NO + NO + IBCocoaTouchFramework + 0 + 3 + + 1 + Custom view + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + + + {320, 368} + + + 1 + MC44ODYyNzQ1MDk4IDAuOTA1ODgyMzUyOSAwLjkyOTQxMTc2NDcAA + NO - 0 - 3 - - Helvetica-Bold - 15 - 16 - - 1 - Simple indeterminate progress - - 1 - MSAxIDEAA - - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - - - 3 - MAA - - - - - 294 - {{20, 68}, {280, 40}} - - NO - NO - 0 - 3 - - 1 - With label - - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - - - - - - 294 - {{20, 116}, {280, 40}} - - NO - NO - 0 - 3 - - 1 - With details label - With details label - With details label - With details label - - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - - - - - - 294 - {{20, 164}, {280, 40}} - - NO - NO - 0 - 3 - - 1 - Determinate mode - - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - - - - - - 294 - {{20, 260}, {280, 40}} - - NO - NO - 0 - 3 - - 1 - Mode switching - - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - - - - - - 294 - {{20, 212}, {280, 40}} - - NO - NO - 0 - 3 - - 1 - Custom view - - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - - + + IBCocoaTouchFramework {320, 460} - - 1 - MC44ODYyNzQ1MDk4IDAuOTA1ODgyMzUyOSAwLjkyOTQxMTc2NDcAA - - NO - + YES + YES + IBCocoaTouchFramework YES - - - view - - - - 7 - showSimple: @@ -243,6 +276,23 @@ 47 + + + showUsingBlocks: + + + 7 + + 51 + + + + view + + + + 70 + @@ -265,48 +315,63 @@ - 6 - + 52 + + + YES + + + + + + 54 + YES - + + - - - - 20 - - - - - 16 - - - - - 10 - - - - - 9 - - + 8 - + + + + 9 + + + + + 10 + + + + + 16 + + + + + 20 + + + + + 49 + + 43 - + @@ -320,8 +385,11 @@ 16.IBPluginDependency 20.IBPluginDependency 43.IBPluginDependency - 6.IBEditorWindowLastContentRect - 6.IBPluginDependency + 49.IBPluginDependency + 52.IBEditorWindowLastContentRect + 52.IBPluginDependency + 54.IBEditorWindowLastContentRect + 54.IBPluginDependency 8.IBPluginDependency 9.IBPluginDependency @@ -333,7 +401,10 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - {{179, 181}, {320, 480}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + {{245, 110}, {320, 460}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + {{217, 96}, {320, 480}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -355,7 +426,7 @@ - 48 + 70 @@ -368,12 +439,12 @@ YES showSimple: + showUsingBlocks: showWithCustomView: showWithDetailsLabel: showWithLabel: showWithLabelDeterminate: showWithLabelMixed: - showWithLabelOnly: YES @@ -386,21 +457,256 @@ id + + YES + + YES + showSimple: + showUsingBlocks: + showWithCustomView: + showWithDetailsLabel: + showWithLabel: + showWithLabelDeterminate: + showWithLabelMixed: + + + YES + + showSimple: + id + + + showUsingBlocks: + id + + + showWithCustomView: + id + + + showWithDetailsLabel: + id + + + showWithLabel: + id + + + showWithLabelDeterminate: + id + + + showWithLabelMixed: + id + + + IBProjectSource Classes/HudDemoViewController.h + + YES + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIAccessibility.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UINibLoading.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UIButton + UIControl + + IBFrameworkSource + UIKit.framework/Headers/UIButton.h + + + + UIControl + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIControl.h + + + + UIResponder + NSObject + + + + UIScrollView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIScrollView.h + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UIView + + IBFrameworkSource + UIKit.framework/Headers/UITextField.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UINavigationController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UIPopoverController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UISplitViewController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UITabBarController.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + 0 + IBCocoaTouchFramework com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 @@ -409,6 +715,6 @@ YES HudDemo.xcodeproj 3 - 3.1 + 117 diff --git a/Demo/Icon.png b/Demo/Icon.png new file mode 100644 index 0000000..430cb6c Binary files /dev/null and b/Demo/Icon.png differ diff --git a/Demo/Icon@2x.png b/Demo/Icon@2x.png new file mode 100644 index 0000000..68d2e0b Binary files /dev/null and b/Demo/Icon@2x.png differ diff --git a/Demo/Info.plist b/Demo/Info.plist index fdf8340..cd4302b 100644 --- a/Demo/Info.plist +++ b/Demo/Info.plist @@ -11,7 +11,7 @@ CFBundleIconFile CFBundleIdentifier - com.yourcompany.${PRODUCT_NAME:identifier} + com.bukovinski.${PRODUCT_NAME:identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Demo/MainWindow.xib b/Demo/MainWindow.xib index b72ae0d..e8a8990 100644 --- a/Demo/MainWindow.xib +++ b/Demo/MainWindow.xib @@ -1,31 +1,43 @@ - + 528 - 9E17 - 672 - 949.33 - 352.00 + 10F569 + 788 + 1038.29 + 461.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 117 + YES - YES com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + YES + + YES + + + YES + + YES IBFilesOwner + IBCocoaTouchFramework IBFirstResponder + IBCocoaTouchFramework - - - HudDemoViewController - + + IBCocoaTouchFramework @@ -33,11 +45,46 @@ {320, 480} 1 - MSAxIDEAA + MC44ODYyNzQ1MDk4IDAuOTA1ODgyMzUyOSAwLjkyOTQxMTc2NDcAA NO NO + IBCocoaTouchFramework + + + + + 1 + + IBCocoaTouchFramework + NO + + + 256 + {0, 0} + NO + YES + YES + IBCocoaTouchFramework + + + YES + + MBProgressHUD + + MBProgressHUD + IBCocoaTouchFramework + + + HudDemoViewController + + 1 + + IBCocoaTouchFramework + NO + + @@ -51,14 +98,6 @@ 4 - - - viewController - - - - 11 - window @@ -67,58 +106,91 @@ 14 + + + navController + + + + 19 + YES 0 - - YES - + -1 - - RmlsZSdzIE93bmVyA + + File's Owner 3 - + HudDemo App Delegate -2 - - - - 10 - - + 12 - + + + + 15 + + + YES + + + + + + + 16 + + + YES + + + + + + 17 + + + + + 18 + + YES - + YES -1.CustomClassName -2.CustomClassName - 10.CustomClassName - 10.IBEditorWindowLastContentRect - 10.IBPluginDependency 12.IBEditorWindowLastContentRect 12.IBPluginDependency + 15.IBEditorWindowLastContentRect + 15.IBPluginDependency + 16.CustomClassName + 16.IBPluginDependency + 17.IBPluginDependency + 18.IBPluginDependency 3.CustomClassName 3.IBPluginDependency @@ -126,20 +198,21 @@ YES UIApplication UIResponder - HudDemoViewController - {{512, 351}, {320, 480}} - com.apple.InterfaceBuilder.IBCocoaTouchPlugin {{525, 346}, {320, 480}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin + {{150, 451}, {320, 480}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + HudDemoViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin HudDemoAppDelegate com.apple.InterfaceBuilder.IBCocoaTouchPlugin YES - - YES - + YES @@ -147,15 +220,13 @@ YES - - YES - + YES - 14 + 19 @@ -165,17 +236,36 @@ NSObject YES - + YES - viewController + navController window YES - HudDemoViewController + UINavigationController UIWindow + + YES + + YES + navController + window + + + YES + + navController + UINavigationController + + + window + UIWindow + + + IBProjectSource Classes/HudDemoAppDelegate.h @@ -192,15 +282,313 @@ HudDemoViewController UIViewController + + YES + + YES + showSimple: + showUsingBlocks: + showWithCustomView: + showWithDetailsLabel: + showWithLabel: + showWithLabelDeterminate: + showWithLabelMixed: + + + YES + id + id + id + id + id + id + id + + + + YES + + YES + showSimple: + showUsingBlocks: + showWithCustomView: + showWithDetailsLabel: + showWithLabel: + showWithLabelDeterminate: + showWithLabelMixed: + + + YES + + showSimple: + id + + + showUsingBlocks: + id + + + showWithCustomView: + id + + + showWithDetailsLabel: + id + + + showWithLabel: + id + + + showWithLabelDeterminate: + id + + + showWithLabelMixed: + id + + + IBProjectSource Classes/HudDemoViewController.h + + YES + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIAccessibility.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UINibLoading.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UIApplication + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIApplication.h + + + + UIBarButtonItem + UIBarItem + + IBFrameworkSource + UIKit.framework/Headers/UIBarButtonItem.h + + + + UIBarItem + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIBarItem.h + + + + UINavigationBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UINavigationBar.h + + + + UINavigationController + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UINavigationController.h + + + + UINavigationItem + NSObject + + + + UIResponder + NSObject + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UIView + + IBFrameworkSource + UIKit.framework/Headers/UITextField.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UIPopoverController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UISplitViewController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UITabBarController.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + + UIWindow + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIWindow.h + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES HudDemo.xcodeproj 3 + 117 diff --git a/MBProgressHUD.h b/MBProgressHUD.h index b5dba35..722444c 100644 --- a/MBProgressHUD.h +++ b/MBProgressHUD.h @@ -131,10 +131,35 @@ typedef enum { UIFont *detailsLabelFont; BOOL isFinished; + BOOL removeFromSuperViewOnHide; UIView *customView; } +/** + * Creates a new hud, adds it to provided view and shows it. The counterpart to this method is hideHUDForView:animated:. + * + * @param view The view that the HUD will be added to + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use + * animations while disappearing. + * @return A reference to the created HUD. + * + * @see hideHUDForView:animated: + */ ++ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated; + +/** + * Finds a HUD sibview and hides it. The counterpart to this method is showHUDAddedTo:animated:. + * + * @param view The view that is going to be searched for a HUD subview. + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use + * animations while disappearing. + * @return YES if a HUD was found and removed, NO otherwise. + * + * @see hideHUDForView:animated: + */ ++ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated; + /** * A convenience constructor that initializes the HUD with the window's bounds. Calls the designated constructor with * window.bounds as the parameter. @@ -238,6 +263,12 @@ typedef enum { */ @property (assign) BOOL taskInProgress; +/** + * Removes the HUD from it's parent view when hidden. + * Defaults to NO. + */ +@property (assign) BOOL removeFromSuperViewOnHide; + /** * Font to be used for the main label. Set this property if the default is not adequate. */ @@ -258,8 +289,8 @@ typedef enum { * the user interface can be updated. Call this method when your task is already set-up to be executed in a new thread * (e.g., when using something like NSOperation or calling an asynchronous call like NSUrlRequest). * - * @param animated If set to YES the HUD will appear using a fade animation. If set to NO the HUD will not use - * animations while appearing. + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use + * animations while disappearing. */ - (void)show:(BOOL)animated; @@ -267,7 +298,7 @@ typedef enum { * Hide the HUD, this still calls the hudWasHidden delegate. This is the counterpart of the hide: method. Use it to * hide the HUD when your task completes. * - * @param animated If set to YES the HUD will disappear using a fade animation. If set to NO the HUD will not use + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use * animations while disappearing. */ - (void)hide:(BOOL)animated; @@ -281,8 +312,8 @@ typedef enum { * @param method The method to be executed while the HUD is shown. This method will be executed in a new thread. * @param target The object that the target method belongs to. * @param object An optional object to be passed to the method. - * @param animated If set to YES the HUD will appear and disappear using a fade animation. If set to NO the HUD will - * not use animations while appearing and disappearing. + * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use + * animations while disappearing. */ - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated; diff --git a/MBProgressHUD.m b/MBProgressHUD.m index 793b260..ddb2392 100644 --- a/MBProgressHUD.m +++ b/MBProgressHUD.m @@ -53,6 +53,7 @@ @synthesize graceTimer; @synthesize minShowTimer; @synthesize taskInProgress; +@synthesize removeFromSuperViewOnHide; @synthesize customView; @@ -66,9 +67,15 @@ mode = newMode; - [self performSelectorOnMainThread:@selector(updateIndicators) withObject:nil waitUntilDone:NO]; - [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO]; - [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; + if ([NSThread isMainThread]) { + [self updateIndicators]; + [self setNeedsLayout]; + [self setNeedsDisplay]; + } else { + [self performSelectorOnMainThread:@selector(updateIndicators) withObject:nil waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; + } } - (MBProgressHUDMode)mode { @@ -76,9 +83,15 @@ } - (void)setLabelText:(NSString *)newText { - [self performSelectorOnMainThread:@selector(updateLabelText:) withObject:newText waitUntilDone:NO]; - [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO]; - [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; + if ([NSThread isMainThread]) { + [self updateLabelText:newText]; + [self setNeedsLayout]; + [self setNeedsDisplay]; + } else { + [self performSelectorOnMainThread:@selector(updateLabelText:) withObject:newText waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; + } } - (NSString *)labelText { @@ -86,9 +99,15 @@ } - (void)setDetailsLabelText:(NSString *)newText { - [self performSelectorOnMainThread:@selector(updateDetailsLabelText:) withObject:newText waitUntilDone:NO]; - [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO]; - [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; + if ([NSThread isMainThread]) { + [self updateDetailsLabelText:newText]; + [self setNeedsLayout]; + [self setNeedsDisplay]; + } else { + [self performSelectorOnMainThread:@selector(updateDetailsLabelText:) withObject:newText waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; + } } - (NSString *)detailsLabelText { @@ -100,8 +119,13 @@ // Update display ony if showing the determinate progress view if (mode == MBProgressHUDModeDeterminate) { - [self performSelectorOnMainThread:@selector(updateProgress) withObject:nil waitUntilDone:NO]; - [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; + if ([NSThread isMainThread]) { + [self updateProgress]; + [self setNeedsDisplay]; + } else { + [self performSelectorOnMainThread:@selector(updateProgress) withObject:nil waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO]; + } } } @@ -161,6 +185,35 @@ #define PI 3.14159265358979323846 + +#pragma mark - +#pragma mark Class methods + ++ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated { + MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view]; + [view addSubview:hud]; + [hud show:animated]; + return [hud autorelease]; +} + ++ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated { + UIView *viewToRemove = nil; + for (UIView *v in [view subviews]) { + if ([v isKindOfClass:[MBProgressHUD class]]) { + viewToRemove = v; + } + } + if (viewToRemove != nil) { + MBProgressHUD *HUD = (MBProgressHUD *)viewToRemove; + HUD.removeFromSuperViewOnHide = YES; + [HUD hide:animated]; + return YES; + } else { + return NO; + } +} + + #pragma mark - #pragma mark Lifecycle methods @@ -191,6 +244,7 @@ self.yOffset = 0.0; self.graceTime = 0.0; self.minShowTime = 0.0; + self.removeFromSuperViewOnHide = NO; self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; @@ -426,6 +480,10 @@ [delegate performSelector:@selector(hudWasHidden)]; } } + + if (removeFromSuperViewOnHide) { + [self removeFromSuperview]; + } } - (void)cleanUp {