From b8e4401c4c23ad117345f4f9f1e0bf6b5207acb4 Mon Sep 17 00:00:00 2001 From: Jonas Gessner Date: Sun, 25 Aug 2013 17:44:38 +0200 Subject: [PATCH] Added 2 new methods, cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added +showWithTitle: and +dismissAfterDelay: • Centralized defines • Separated public from private defines • Moved from float to NSTimeInterval (aka double) for delays --- .../project.pbxproj | 22 +++++- Source/MMHud.h | 27 ------- Source/MMHud.m | 36 +-------- Source/MMLinearProgressView.h | 2 +- Source/MMProgressHUD+Animations.m | 2 + Source/MMProgressHUD+Class.m | 21 +++-- Source/MMProgressHUD.h | 78 +++++++------------ Source/MMProgressHUD.m | 34 +++----- Source/MMProgressHUDDefines-Private.h | 67 ++++++++++++++++ Source/MMProgressHUDDefines-Private.m | 51 ++++++++++++ Source/MMProgressHUDDefines.h | 63 ++++++++++++--- Source/MMProgressHUDDefines.m | 20 +++++ Source/MMProgressHUDViewController.m | 2 + Source/MMProgressHUDWindow.m | 2 + ...ogressView.h => MMProgressView-Protocol.h} | 0 Source/MMRadialProgressView.h | 2 +- 16 files changed, 277 insertions(+), 152 deletions(-) create mode 100644 Source/MMProgressHUDDefines-Private.h create mode 100644 Source/MMProgressHUDDefines-Private.m create mode 100644 Source/MMProgressHUDDefines.m rename Source/{MMProgressView.h => MMProgressView-Protocol.h} (100%) diff --git a/Demo/MMProgressHUDDemo.xcodeproj/project.pbxproj b/Demo/MMProgressHUDDemo.xcodeproj/project.pbxproj index 23d50f2..a46dfa2 100644 --- a/Demo/MMProgressHUDDemo.xcodeproj/project.pbxproj +++ b/Demo/MMProgressHUDDemo.xcodeproj/project.pbxproj @@ -71,6 +71,12 @@ 69DA08D2158261EE000DC29E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69DA08D0158261EE000DC29E /* InfoPlist.strings */; }; 69DA08D5158261EE000DC29E /* MMProgressHUDTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 69DA08D4158261EE000DC29E /* MMProgressHUDTests.m */; }; DDBCC20617C2822A00C3BF8C /* MMLinearProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBCC20417C2822A00C3BF8C /* MMLinearProgressView.m */; }; + DDBE93BE17CA59FD00B78C77 /* MMProgressHUDDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */; }; + DDBE93BF17CA59FE00B78C77 /* MMProgressHUDDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */; }; + DDBE93C017CA59FE00B78C77 /* MMProgressHUDDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */; }; + DDBE93C317CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */; }; + DDBE93C417CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */; }; + DDBE93C517CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -146,7 +152,10 @@ DDB2DD6A17C626570077C18E /* MMProgressHUDDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMProgressHUDDefines.h; sourceTree = ""; }; DDBCC20317C2822A00C3BF8C /* MMLinearProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMLinearProgressView.h; sourceTree = ""; }; DDBCC20417C2822A00C3BF8C /* MMLinearProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MMLinearProgressView.m; sourceTree = ""; }; - DDBCC20517C2822A00C3BF8C /* MMProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMProgressView.h; sourceTree = ""; }; + DDBCC20517C2822A00C3BF8C /* MMProgressView-Protocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MMProgressView-Protocol.h"; sourceTree = ""; }; + DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMProgressHUDDefines.m; sourceTree = ""; }; + DDBE93C117CA5BF300B78C77 /* MMProgressHUDDefines-Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MMProgressHUDDefines-Private.h"; sourceTree = ""; }; + DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MMProgressHUDDefines-Private.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -257,6 +266,9 @@ 46F3F73D16D1E76700E255A2 /* MMVectorImage.h */, 46F3F73E16D1E76700E255A2 /* MMVectorImage.m */, DDB2DD6A17C626570077C18E /* MMProgressHUDDefines.h */, + DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */, + DDBE93C117CA5BF300B78C77 /* MMProgressHUDDefines-Private.h */, + DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */, 46A19B5B155493B500D65BB8 /* MMProgressHUD.h */, 46A19B5C155493B500D65BB8 /* MMProgressHUD.m */, 55AC1A0315A602A500D64C1F /* MMProgressHUDOverlayView.h */, @@ -264,7 +276,7 @@ 55F0596515A20BDD00A47983 /* MMProgressHUD+Class.m */, 55F0595F15A2083C00A47983 /* MMProgressHUD+Animations.h */, 55F0596015A2083C00A47983 /* MMProgressHUD+Animations.m */, - DDBCC20517C2822A00C3BF8C /* MMProgressView.h */, + DDBCC20517C2822A00C3BF8C /* MMProgressView-Protocol.h */, DDBCC20317C2822A00C3BF8C /* MMLinearProgressView.h */, DDBCC20417C2822A00C3BF8C /* MMLinearProgressView.m */, 550D504A15615BEF0092B975 /* MMRadialProgressView.h */, @@ -508,11 +520,13 @@ 46A19B4A155492E000D65BB8 /* MMViewController.m in Sources */, 46A19B5D155493B500D65BB8 /* MMProgressHUD.m in Sources */, 550D504C15615BEF0092B975 /* MMRadialProgressView.m in Sources */, + DDBE93BE17CA59FD00B78C77 /* MMProgressHUDDefines.m in Sources */, 5527AEFB159CD7650037D67D /* MMHud.m in Sources */, 5527AEFF159CD7D50037D67D /* MMProgressHUDWindow.m in Sources */, 5527AF03159CD8200037D67D /* MMProgressHUDViewController.m in Sources */, 55F0596115A2083C00A47983 /* MMProgressHUD+Animations.m in Sources */, 55F0596615A20BDD00A47983 /* MMProgressHUD+Class.m in Sources */, + DDBE93C317CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */, 55AC1A0515A602A500D64C1F /* MMProgressHUDOverlayView.m in Sources */, DDBCC20617C2822A00C3BF8C /* MMLinearProgressView.m in Sources */, 46F3F73F16D1E76700E255A2 /* MMVectorImage.m in Sources */, @@ -528,11 +542,13 @@ 55F0589A159E04E200A47983 /* MMHudTests.m in Sources */, 55F0589B159E058600A47983 /* MMProgressHUD.m in Sources */, 55F0589C159E058600A47983 /* MMRadialProgressView.m in Sources */, + DDBE93C017CA59FE00B78C77 /* MMProgressHUDDefines.m in Sources */, 55F0589D159E058600A47983 /* MMHud.m in Sources */, 55F0589E159E058600A47983 /* MMProgressHUDWindow.m in Sources */, 55F0589F159E058600A47983 /* MMProgressHUDViewController.m in Sources */, 55F0596315A2083C00A47983 /* MMProgressHUD+Animations.m in Sources */, 55F0596815A20BDD00A47983 /* MMProgressHUD+Class.m in Sources */, + DDBE93C517CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */, 55AC1A0615A602A500D64C1F /* MMProgressHUDOverlayView.m in Sources */, 46ACE86C17C50A610075C2A0 /* MMLinearProgressView.m in Sources */, 46F3F74116D1E76700E255A2 /* MMVectorImage.m in Sources */, @@ -548,11 +564,13 @@ 5527AF07159CD97A0037D67D /* MMHudTests.m in Sources */, 55F0592D159E39C400A47983 /* MMProgressHUD.m in Sources */, 55F0592E159E39CB00A47983 /* MMRadialProgressView.m in Sources */, + DDBE93BF17CA59FE00B78C77 /* MMProgressHUDDefines.m in Sources */, 55F0592F159E39CB00A47983 /* MMHud.m in Sources */, 55F05930159E39CB00A47983 /* MMProgressHUDWindow.m in Sources */, 55F05931159E39CB00A47983 /* MMProgressHUDViewController.m in Sources */, 55F0596215A2083C00A47983 /* MMProgressHUD+Animations.m in Sources */, 55F0596715A20BDD00A47983 /* MMProgressHUD+Class.m in Sources */, + DDBE93C417CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */, 55AC1A0815A62B6900D64C1F /* MMProgressHUDOverlayView.m in Sources */, 46ACE86B17C50A580075C2A0 /* MMLinearProgressView.m in Sources */, 46F3F74016D1E76700E255A2 /* MMVectorImage.m in Sources */, diff --git a/Source/MMHud.h b/Source/MMHud.h index 5cd2e24..e7c1e79 100755 --- a/Source/MMHud.h +++ b/Source/MMHud.h @@ -9,33 +9,6 @@ #import #import "MMProgressHUDDefines.h" -MMExtern CGFloat const MMProgressHUDAnimateInDurationLong; -MMExtern CGFloat const MMProgressHUDAnimateInDurationNormal; -MMExtern CGFloat const MMProgressHUDAnimateInDurationMedium; -MMExtern CGFloat const MMProgressHUDAnimateInDurationShort; -MMExtern CGFloat const MMProgressHUDAnimateInDurationVeryShort; - -MMExtern CGFloat const MMProgressHUDAnimateOutDurationLong; -MMExtern CGFloat const MMProgressHUDAnimateOutDurationMedium; -MMExtern CGFloat const MMProgressHUDAnimateOutDurationShort; - -typedef NS_ENUM(NSInteger, MMProgressHUDDisplayStyle) { - MMProgressHUDDisplayStylePlain = 0, - MMProgressHUDDisplayStyleBordered, -}; - -typedef NS_ENUM(NSInteger, MMProgressHUDProgressStyle) { - MMProgressHUDProgressStyleIndeterminate = 0, - MMProgressHUDProgressStyleRadial, - MMProgressHUDProgressStyleLinear, -} DEPRECATED_ATTRIBUTE; - -typedef NS_ENUM(NSInteger, MMProgressHUDCompletionState) { - MMProgressHUDCompletionStateNone = 0, - MMProgressHUDCompletionStateError, - MMProgressHUDCompletionStateSuccess, -}; - @class MMHud; @protocol MMHudDelegate diff --git a/Source/MMHud.m b/Source/MMHud.m index d6e5a27..393c8d5 100755 --- a/Source/MMHud.m +++ b/Source/MMHud.m @@ -9,42 +9,10 @@ #import #import "MMHud.h" #import "MMProgressHUD.h" -#import "MMProgressView.h" +#import "MMProgressView-Protocol.h" #import "MMRadialProgressView.h" -CGFloat const MMProgressHUDDefaultFontSize = 16.f; - -CGFloat const MMProgressHUDMaximumWidth = 300.f; -CGFloat const MMProgressHUDMinimumWidth = 100.f; -CGFloat const MMProgressHUDContentPadding = 5.f; - -CGFloat const MMProgressHUDAnimateInDurationLong = 1.5f; -CGFloat const MMProgressHUDAnimateInDurationMedium = 0.75f; -CGFloat const MMProgressHUDAnimateInDurationNormal = 0.35f; -CGFloat const MMProgressHUDAnimateInDurationShort = 0.25f; -CGFloat const MMProgressHUDAnimateInDurationVeryShort= 0.15f; - -CGFloat const MMProgressHUDAnimateOutDurationLong = 0.75f; -CGFloat const MMProgressHUDAnimateOutDurationMedium = 0.55f; -CGFloat const MMProgressHUDAnimateOutDurationShort = 0.35f; - -CGSize const MMProgressHUDDefaultContentAreaSize = { 100.f, 100.f }; -CGSize const MMProgressHUDProgressContentAreaSize = { 40.f, 40.f }; -CGSize const MMProgressHUDProgressMaximumAreaSize = {200.0f, 200.0f}; - - -NSString * const MMProgressHUDFontNameBold = @"HelveticaNeue-Bold"; -NSString * const MMProgressHUDFontNameNormal = @"HelveticaNeue-Light"; - -#ifdef DEBUG - #ifdef MM_HUD_FRAME_DEBUG - static const BOOL MMProgressHUDFrameDebugModeEnabled = YES; - #else - static const BOOL MMProgressHUDFrameDebugModeEnabled = NO; - #endif -#else - static const BOOL MMProgressHUDFrameDebugModeEnabled = NO; -#endif +#import "MMProgressHUDDefines-Private.h" @interface MMHud() diff --git a/Source/MMLinearProgressView.h b/Source/MMLinearProgressView.h index 026a3d6..86bc199 100644 --- a/Source/MMLinearProgressView.h +++ b/Source/MMLinearProgressView.h @@ -7,7 +7,7 @@ // #import -#import "MMProgressView.h" +#import "MMProgressView-Protocol.h" @interface MMLinearProgressView : UIView diff --git a/Source/MMProgressHUD+Animations.m b/Source/MMProgressHUD+Animations.m index 12712d8..b5190bf 100755 --- a/Source/MMProgressHUD+Animations.m +++ b/Source/MMProgressHUD+Animations.m @@ -8,6 +8,8 @@ #import #import "MMProgressHUD+Animations.h" +#import "MMProgressHUDDefines-Private.h" + @interface MMProgressHUD () - (CGPoint)_windowCenterForHUDAnchor:(CGPoint)anchor; diff --git a/Source/MMProgressHUD+Class.m b/Source/MMProgressHUD+Class.m index 3bf3afa..d9b9e91 100755 --- a/Source/MMProgressHUD+Class.m +++ b/Source/MMProgressHUD+Class.m @@ -7,6 +7,7 @@ // #import "MMProgressHUD.h" +#import "MMProgressHUDDefines-Private.h" @interface MMProgressHUD() @@ -14,13 +15,14 @@ - (CGPoint)_windowCenterForHUDAnchor:(CGPoint)anchor; - (void)dismissWithCompletionState:(MMProgressHUDCompletionState)completionState title:(NSString *)title status:(NSString *)status - afterDelay:(float)delay; + afterDelay:(NSTimeInterval)delay; - (void)_updateHUDAnimated:(BOOL)animated withCompletion:(void(^)(BOOL completed))completionBlock; - (void)show; - (void)dismiss; +- (void)dismissAfterDelay:(NSTimeInterval)delay; @end @@ -109,6 +111,11 @@ + (void)updateProgress:(CGFloat)progress { } //indeterminate status ++ (void)showWithTitle:(NSString *)title { + [MMProgressHUD showWithTitle:title + status:nil]; +} + + (void)showWithStatus:(NSString *)status { [MMProgressHUD showWithTitle:nil status:status]; @@ -222,7 +229,7 @@ + (void)showWithTitle:(NSString *)title //dismissal + (void)dismissWithError:(NSString *)status title:(NSString *)title - afterDelay:(float)delay { + afterDelay:(NSTimeInterval)delay { if ([NSThread isMainThread] == NO) { dispatch_sync(dispatch_get_main_queue(), ^{ [[MMProgressHUD sharedHUD] dismissWithCompletionState:MMProgressHUDCompletionStateError @@ -252,7 +259,7 @@ + (void)dismissWithError:(NSString *)status { } + (void)dismissWithError:(NSString *)status - afterDelay:(float)delay { + afterDelay:(NSTimeInterval)delay { [MMProgressHUD dismissWithError:status title:nil afterDelay:delay]; @@ -260,7 +267,7 @@ + (void)dismissWithError:(NSString *)status + (void)dismissWithSuccess:(NSString *)status title:(NSString *)title - afterDelay:(float)delay { + afterDelay:(NSTimeInterval)delay { if ([NSThread isMainThread] == NO) { dispatch_sync(dispatch_get_main_queue(), ^{ [[MMProgressHUD sharedHUD] dismissWithCompletionState:MMProgressHUDCompletionStateSuccess @@ -289,10 +296,14 @@ + (void)dismissWithSuccess:(NSString *)status { title:nil]; } ++ (void)dismissAfterDelay:(NSTimeInterval)delay { + [[MMProgressHUD sharedHUD] dismissAfterDelay:delay]; +} + + (void)dismiss { if ([NSThread isMainThread] == NO) { dispatch_sync(dispatch_get_main_queue(), ^{ - [[MMProgressHUD sharedHUD] dismiss]; + [[MMProgressHUD sharedHUD] dismiss]; }); } else { diff --git a/Source/MMProgressHUD.h b/Source/MMProgressHUD.h index 91ac522..7a331b3 100755 --- a/Source/MMProgressHUD.h +++ b/Source/MMProgressHUD.h @@ -9,44 +9,9 @@ #import #import "MMHud.h" -MMExtern NSString * const MMProgressHUDDefaultConfirmationMessage; - -MMExtern NSString * const MMProgressHUDAnimationShow; -MMExtern NSString * const MMProgressHUDAnimationDismiss; -MMExtern NSString * const MMProgressHUDAnimationWindowFadeOut; -MMExtern NSString * const MMProgressHUDAnimationKeyShowAnimation; -MMExtern NSString * const MMProgressHUDAnimationKeyDismissAnimation; - - -MMExtern float const MMProgressHUDStandardDismissDelay; - @class MMProgressHUDWindow; @class MMProgressHUDOverlayView; -typedef NS_ENUM(NSInteger, MMProgressHUDPresentationStyle) { - MMProgressHUDPresentationStyleDrop = 0, //default - MMProgressHUDPresentationStyleExpand, - MMProgressHUDPresentationStyleShrink, - MMProgressHUDPresentationStyleSwingLeft, - MMProgressHUDPresentationStyleSwingRight, - MMProgressHUDPresentationStyleBalloon, - MMProgressHUDPresentationStyleFade, - MMProgressHUDPresentationStyleNone -}; - -typedef NS_ENUM(NSInteger, MMProgressHUDWindowOverlayMode) { - MMProgressHUDWindowOverlayModeNone = -1, - MMProgressHUDWindowOverlayModeGradient = 0, - MMProgressHUDWindowOverlayModeLinear, - /*MMProgressHUDWindowOverlayModeBlur*/ //iOS 7 only -}; - -//iOS 7 only -//typedef NS_ENUM(NSInteger, MMProgressHUDOptions) { -// MMProgressHUDOptionGravityEnabled = 1 << 0, -// MMProgressHUDOptionGyroEnabled = 1 << 1, -//}; - @interface MMProgressHUD : UIView /** An enum to specify the style in which to display progress. @@ -164,6 +129,27 @@ This message will be presented to the user when a cancelBlock is present after t /** @name Presentation */ //----------------------------------------------- + +/** Shows indeterminate HUD with specified title. + + @warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call. + + @param title Title to display. + */ ++ (void)showWithTitle:(NSString *)title; + + +/** Shows user-blocking HUD with only a status message. + + Since the title of this HUD is nil, the status message font will become bold by default. + + @warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call. + + @param status Status message to display. + */ ++ (void)showWithStatus:(NSString *)status; + + /** Shows indeterminate HUD with specified title and status. When the title of the HUD is nil, the status message font will become bold by default. @@ -301,16 +287,6 @@ This message will be presented to the user when a cancelBlock is present after t status:(NSString *)status images:(NSArray *)images; -/** Shows user-blocking HUD with only a status message. - - Since the title of this HUD is nil, the status message font will become bold by default. - - @warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call. - - @param status Status message to display. - */ -+ (void)showWithStatus:(NSString *)status; - //----------------------------------------------- /** @name Dismissal */ //----------------------------------------------- @@ -318,6 +294,12 @@ This message will be presented to the user when a cancelBlock is present after t /** Dismisses the shared HUD with the current presentationStyle and default delay. */ + (void)dismiss; + +/** Dismisses the shared HUD with the current presentationStyle and specified delay. + @param delay Delay to wait before animating the dismiss of the HUD. + */ ++ (void)dismissAfterDelay:(NSTimeInterval)delay; + #pragma mark - Dismiss with Error /** Dismisses the shared HUD with the current presentationStyle in an error-state after a user-specified delay. @@ -328,7 +310,7 @@ This message will be presented to the user when a cancelBlock is present after t */ + (void)dismissWithError:(NSString *)message title:(NSString *)title - afterDelay:(float)delay; + afterDelay:(NSTimeInterval)delay; /** Dismisses the shared HUD with the current presentationStyle in an error-state after a standard delay. @@ -350,7 +332,7 @@ This message will be presented to the user when a cancelBlock is present after t @param delay Delay to wait before animating the dismiss of the HUD. */ + (void)dismissWithError:(NSString *)message - afterDelay:(float)delay; + afterDelay:(NSTimeInterval)delay; #pragma mark - Dismiss with Success /** Dismisses the shared HUD with the current presentationStyle in a success-state after a user-specified delay. @@ -361,7 +343,7 @@ This message will be presented to the user when a cancelBlock is present after t */ + (void)dismissWithSuccess:(NSString *)message title:(NSString *)title - afterDelay:(float)delay; + afterDelay:(NSTimeInterval)delay; /** Dismisses the shared HUD with the current presentationStyle in a success-state. diff --git a/Source/MMProgressHUD.m b/Source/MMProgressHUD.m index 95435cb..90ea5d9 100755 --- a/Source/MMProgressHUD.m +++ b/Source/MMProgressHUD.m @@ -20,24 +20,7 @@ #import "MMLinearProgressView.h" #import "MMRadialProgressView.h" -#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 -#error MMProgressHUD uses APIs only available in iOS 5.0+ -#endif - -static const BOOL kMMProgressHUDDebugMode = NO; - -NSString * const MMProgressHUDDefaultConfirmationMessage = @"Cancel?"; -NSString * const MMProgressHUDAnimationShow = @"mm-progress-hud-present-animation"; -NSString * const MMProgressHUDAnimationDismiss = @"mm-progress-hud-dismiss-animation"; -NSString * const MMProgressHUDAnimationWindowFadeOut = @"mm-progress-hud-window-fade-out"; -NSString * const MMProgressHUDAnimationKeyShowAnimation = @"show"; -NSString * const MMProgressHUDAnimationKeyDismissAnimation = @"dismiss"; - -NSUInteger const MMProgressHUDConfirmationPulseCount = 8;//Keep this number even - -CGFloat const MMProgressHUDStandardDismissDelay = 0.75f; - -CGSize const MMProgressHUDDefaultImageSize = {37.f, 37.f}; +#import "MMProgressHUDDefines-Private.h" #pragma mark - MMProgressHUD @interface MMProgressHUD () @@ -129,7 +112,7 @@ - (void)showWithTitle:(NSString *)title - (void)dismissWithCompletionState:(MMProgressHUDCompletionState)completionState title:(NSString *)title status:(NSString *)status - afterDelay:(float)delay { + afterDelay:(NSTimeInterval)delay { if (title) { self.title = title; } @@ -544,7 +527,7 @@ - (void)show { }]; } -- (void)dismiss { +- (void)dismissAfterDelay:(NSTimeInterval)delay { NSAssert([NSThread isMainThread], @"Dismiss method should be run on main thread!"); MMHudLog(@"Dismissing..."); @@ -584,14 +567,13 @@ - (void)dismiss { break; } - CGFloat duration = (self.presentationStyle == MMProgressHUDPresentationStyleNone) ? 0.f : MMProgressHUDAnimateOutDurationLong; - CGFloat delay = (self.presentationStyle == MMProgressHUDPresentationStyleDrop) ? MMProgressHUDAnimateOutDurationShort : 0.f; + NSTimeInterval duration = (self.presentationStyle == MMProgressHUDPresentationStyleNone) ? 0.0 : MMProgressHUDAnimateOutDurationLong; [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseIn | - UIViewAnimationOptionBeginFromCurrentState + UIViewAnimationOptionBeginFromCurrentState animations:^{ self.overlayView.alpha = 0.f; } @@ -610,6 +592,12 @@ - (void)dismiss { }]; } +- (void)dismiss { + NSTimeInterval delay = (self.presentationStyle == MMProgressHUDPresentationStyleDrop) ? MMProgressHUDAnimateOutDurationShort : 0.0; + + [self dismissAfterDelay:delay]; +} + - (CGPoint)_antialiasedPositionPointForPoint:(CGPoint)oldCenter forLayer:(CALayer *)layer { CGPoint newCenter = oldCenter; diff --git a/Source/MMProgressHUDDefines-Private.h b/Source/MMProgressHUDDefines-Private.h new file mode 100644 index 0000000..4e41919 --- /dev/null +++ b/Source/MMProgressHUDDefines-Private.h @@ -0,0 +1,67 @@ +// +// MMProgressHUDDefines-Private.h +// MMProgressHUDDemo +// +// Created by Jonas Gessner on 25.08.13. +// Copyright (c) 2013 Jonas Gessner. All rights reserved. +// + + +#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 +#error MMProgressHUD uses APIs only available in iOS 5.0+ +#endif + + +#import "MMProgressHUDDefines.h" + +#ifdef DEBUG +#ifdef MM_HUD_DEBUG +#define MMHudLog(fmt, ...) NSLog((@"%@ [line %u]: " fmt), NSStringFromClass(self.class), __LINE__, ##__VA_ARGS__) +#else +#define MMHudLog(...) +#endif +#else +#define MMHudLog(...) +#endif + +#define MMHudWLog(fmt, ...) NSLog((@"%@ WARNING [line %u]: " fmt), NSStringFromClass(self.class), __LINE__, ##__VA_ARGS__) + + +MMExtern BOOL const kMMProgressHUDDebugMode; + +MMExtern NSString * const MMProgressHUDDefaultConfirmationMessage; +MMExtern NSString * const MMProgressHUDAnimationShow; +MMExtern NSString * const MMProgressHUDAnimationDismiss; +MMExtern NSString * const MMProgressHUDAnimationWindowFadeOut; +MMExtern NSString * const MMProgressHUDAnimationKeyShowAnimation; +MMExtern NSString * const MMProgressHUDAnimationKeyDismissAnimation; + +MMExtern NSUInteger const MMProgressHUDConfirmationPulseCount;//Keep this number even + +MMExtern NSTimeInterval const MMProgressHUDStandardDismissDelay; + +MMExtern CGSize const MMProgressHUDDefaultImageSize; + + +MMExtern CGFloat const MMProgressHUDDefaultFontSize; + +MMExtern CGFloat const MMProgressHUDMaximumWidth; +MMExtern CGFloat const MMProgressHUDMinimumWidth; +MMExtern CGFloat const MMProgressHUDContentPadding; +MMExtern CGSize const MMProgressHUDDefaultContentAreaSize; +MMExtern CGSize const MMProgressHUDProgressContentAreaSize; +MMExtern CGSize const MMProgressHUDProgressMaximumAreaSize; + +MMExtern NSString * const MMProgressHUDFontNameBold; +MMExtern NSString * const MMProgressHUDFontNameNormal; + +#ifdef DEBUG +#ifdef MM_HUD_FRAME_DEBUG +MMExtern BOOL const MMProgressHUDFrameDebugModeEnabled; +#else +MMExtern BOOL const MMProgressHUDFrameDebugModeEnabled; +#endif +#else +MMExtern BOOL const MMProgressHUDFrameDebugModeEnabled; +#endif + diff --git a/Source/MMProgressHUDDefines-Private.m b/Source/MMProgressHUDDefines-Private.m new file mode 100644 index 0000000..49ac263 --- /dev/null +++ b/Source/MMProgressHUDDefines-Private.m @@ -0,0 +1,51 @@ +// +// MMProgressHUDDefines-Private.m +// MMProgressHUDDemo +// +// Created by Jonas Gessner on 25.08.13. +// Copyright (c) 2013 Jonas Gessner. All rights reserved. +// + +#import "MMProgressHUDDefines-Private.h" + + +BOOL const kMMProgressHUDDebugMode = NO; + +NSString * const MMProgressHUDDefaultConfirmationMessage = @"Cancel?"; +NSString * const MMProgressHUDAnimationShow = @"mm-progress-hud-present-animation"; +NSString * const MMProgressHUDAnimationDismiss = @"mm-progress-hud-dismiss-animation"; +NSString * const MMProgressHUDAnimationWindowFadeOut = @"mm-progress-hud-window-fade-out"; +NSString * const MMProgressHUDAnimationKeyShowAnimation = @"show"; +NSString * const MMProgressHUDAnimationKeyDismissAnimation = @"dismiss"; + + +NSUInteger const MMProgressHUDConfirmationPulseCount = 8;//Keep this number even + +NSTimeInterval const MMProgressHUDStandardDismissDelay = 0.75; + +CGSize const MMProgressHUDDefaultImageSize = {37.f, 37.f}; + + +CGFloat const MMProgressHUDDefaultFontSize = 16.f; + +CGFloat const MMProgressHUDMaximumWidth = 300.f; +CGFloat const MMProgressHUDMinimumWidth = 100.f; +CGFloat const MMProgressHUDContentPadding = 5.f; +CGSize const MMProgressHUDDefaultContentAreaSize = { 100.f, 100.f }; +CGSize const MMProgressHUDProgressContentAreaSize = { 40.f, 40.f }; +CGSize const MMProgressHUDProgressMaximumAreaSize = {200.0f, 200.0f}; + + +NSString * const MMProgressHUDFontNameBold = @"HelveticaNeue-Bold"; +NSString * const MMProgressHUDFontNameNormal = @"HelveticaNeue-Light"; + + +#ifdef DEBUG +#ifdef MM_HUD_FRAME_DEBUG +BOOL const MMProgressHUDFrameDebugModeEnabled; +#else +BOOL const MMProgressHUDFrameDebugModeEnabled; +#endif +#else +BOOL const MMProgressHUDFrameDebugModeEnabled; +#endif \ No newline at end of file diff --git a/Source/MMProgressHUDDefines.h b/Source/MMProgressHUDDefines.h index aeeda23..46def04 100644 --- a/Source/MMProgressHUDDefines.h +++ b/Source/MMProgressHUDDefines.h @@ -6,20 +6,61 @@ // Copyright (c) 2013 Jonas Gessner. All rights reserved. // -#ifdef DEBUG -#ifdef MM_HUD_DEBUG -#define MMHudLog(fmt, ...) NSLog((@"%@ [line %u]: " fmt), NSStringFromClass(self.class), __LINE__, ##__VA_ARGS__) -#else -#define MMHudLog(...) -#endif -#else -#define MMHudLog(...) -#endif +typedef NS_ENUM(NSInteger, MMProgressHUDPresentationStyle) { + MMProgressHUDPresentationStyleDrop = 0, //default + MMProgressHUDPresentationStyleExpand, + MMProgressHUDPresentationStyleShrink, + MMProgressHUDPresentationStyleSwingLeft, + MMProgressHUDPresentationStyleSwingRight, + MMProgressHUDPresentationStyleBalloon, + MMProgressHUDPresentationStyleFade, + MMProgressHUDPresentationStyleNone +}; + +typedef NS_ENUM(NSInteger, MMProgressHUDWindowOverlayMode) { + MMProgressHUDWindowOverlayModeNone = -1, + MMProgressHUDWindowOverlayModeGradient = 0, + MMProgressHUDWindowOverlayModeLinear, + /*MMProgressHUDWindowOverlayModeBlur*/ //iOS 7 only +}; + +typedef NS_ENUM(NSInteger, MMProgressHUDDisplayStyle) { + MMProgressHUDDisplayStylePlain = 0, + MMProgressHUDDisplayStyleBordered, +}; + +typedef NS_ENUM(NSInteger, MMProgressHUDProgressStyle) { + MMProgressHUDProgressStyleIndeterminate = 0, + MMProgressHUDProgressStyleRadial, + MMProgressHUDProgressStyleLinear, +} DEPRECATED_ATTRIBUTE; -#define MMHudWLog(fmt, ...) NSLog((@"%@ WARNING [line %u]: " fmt), NSStringFromClass(self.class), __LINE__, ##__VA_ARGS__) +typedef NS_ENUM(NSInteger, MMProgressHUDCompletionState) { + MMProgressHUDCompletionStateNone = 0, + MMProgressHUDCompletionStateError, + MMProgressHUDCompletionStateSuccess, +}; + +//iOS 7 only +//typedef NS_ENUM(NSInteger, MMProgressHUDOptions) { +// MMProgressHUDOptionGravityEnabled = 1 << 0, +// MMProgressHUDOptionGyroEnabled = 1 << 1, +//}; #ifdef __cplusplus #define MMExtern extern "C" #else #define MMExtern extern -#endif \ No newline at end of file +#endif + +MMExtern NSTimeInterval const MMProgressHUDAnimateInDurationLong; +MMExtern NSTimeInterval const MMProgressHUDAnimateInDurationMedium; +MMExtern NSTimeInterval const MMProgressHUDAnimateInDurationNormal; +MMExtern NSTimeInterval const MMProgressHUDAnimateInDurationShort; +MMExtern NSTimeInterval const MMProgressHUDAnimateInDurationVeryShort; + +MMExtern NSTimeInterval const MMProgressHUDAnimateOutDurationLong; +MMExtern NSTimeInterval const MMProgressHUDAnimateOutDurationMedium; +MMExtern NSTimeInterval const MMProgressHUDAnimateOutDurationShort; + + diff --git a/Source/MMProgressHUDDefines.m b/Source/MMProgressHUDDefines.m new file mode 100644 index 0000000..91853ea --- /dev/null +++ b/Source/MMProgressHUDDefines.m @@ -0,0 +1,20 @@ +// +// MMProgressHUDDefines.m +// MMProgressHUDDemo +// +// Created by Jonas Gessner on 25.08.13. +// Copyright (c) 2013 Jonas Gessner. All rights reserved. +// + +#import "MMProgressHUDDefines.h" + +NSTimeInterval const MMProgressHUDAnimateInDurationLong = 1.5; +NSTimeInterval const MMProgressHUDAnimateInDurationMedium = 0.75; +NSTimeInterval const MMProgressHUDAnimateInDurationNormal = 0.35; +NSTimeInterval const MMProgressHUDAnimateInDurationShort = 0.25; +NSTimeInterval const MMProgressHUDAnimateInDurationVeryShort = 0.15; + +NSTimeInterval const MMProgressHUDAnimateOutDurationLong = 0.75; +NSTimeInterval const MMProgressHUDAnimateOutDurationMedium = 0.55; +NSTimeInterval const MMProgressHUDAnimateOutDurationShort = 0.35; + diff --git a/Source/MMProgressHUDViewController.m b/Source/MMProgressHUDViewController.m index 0a2dca2..8364ecb 100755 --- a/Source/MMProgressHUDViewController.m +++ b/Source/MMProgressHUDViewController.m @@ -10,6 +10,8 @@ #import "MMProgressHUDWindow.h" #import "MMProgressHUD.h" +#import "MMProgressHUDDefines-Private.h" + #define suppressDeprecation(Stuff) \ do { \ diff --git a/Source/MMProgressHUDWindow.m b/Source/MMProgressHUDWindow.m index d094066..0023dac 100755 --- a/Source/MMProgressHUDWindow.m +++ b/Source/MMProgressHUDWindow.m @@ -8,6 +8,8 @@ #import "MMProgressHUDWindow.h" +#import "MMProgressHUDDefines-Private.h" + @implementation MMProgressHUDWindow - (instancetype)init { diff --git a/Source/MMProgressView.h b/Source/MMProgressView-Protocol.h similarity index 100% rename from Source/MMProgressView.h rename to Source/MMProgressView-Protocol.h diff --git a/Source/MMRadialProgressView.h b/Source/MMRadialProgressView.h index e860d3c..f96d545 100755 --- a/Source/MMRadialProgressView.h +++ b/Source/MMRadialProgressView.h @@ -7,7 +7,7 @@ // #import -#import "MMProgressView.h" +#import "MMProgressView-Protocol.h" @interface MMRadialProgressView : UIView