diff --git a/Demo/Demo.gif b/Demo/Demo.gif deleted file mode 100644 index 8b737f7..0000000 Binary files a/Demo/Demo.gif and /dev/null differ diff --git a/Demo/LICENSE b/Demo/LICENSE deleted file mode 100644 index c55cc92..0000000 --- a/Demo/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2015 Wilson-yuan - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/Demo/README.md b/Demo/README.md deleted file mode 100644 index b47e662..0000000 --- a/Demo/README.md +++ /dev/null @@ -1,77 +0,0 @@ -# WSProgressHUD -This is a beauful hud view for iPhone & iPad - -![Demo](https://raw.githubusercontent.com/devSC/WSProgressHUD/master/Demo/Demo.gif) - -#Usage -To run the WSProgressHUD project - -``` objc -//Show on the self.view - -@implementation ViewController -{ - WSProgressHUD *hud; -} -- (void)viewDidLoad { - [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. - - //Add HUD to view - hud = [[WSProgressHUD alloc] initWithView:self.navigationController.view]; - [self.view addSubview:hud]; - - //show - [hud showWithString:@"Wating..." maskType:WSProgressHUDMaskTypeBlack]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [hud dismiss]; - }); - -} - -//Show on the window - //show - [WSProgressHUD show]; - - //Show with mask - [WSProgressHUD showWithMaskType:WSProgressHUDMaskTypeBlack]; - - //Show with mask without tabbar - [WSProgressHUD showWithStatus:@"Loading..." maskType:WSProgressHUDMaskTypeBlack maskWithout:WSProgressHUDMaskWithoutTabbar]; - - //Show with string - [WSProgressHUD showWithStatus:@"Loading..."]; - - //Show with facebook shimmering - [WSProgressHUD showShimmeringString:@"WSProgressHUD Loading..."]; - - //Show with Progress - [WSProgressHUD showProgress:progress status:@"Updating..."]; - - //Show with image - [WSProgressHUD showSuccessWithStatus:@"Thanks.."]; - - //Show with string - [WSProgressHUD showImage:nil status:@"WSProgressHUD"] - - //Dismiss - [WSProgressHUD dismiss]; -``` - -##Thanks - -@Shimmering -@SVProgressHUD -@MMMaterialDesignSpinner - -## Author -Wilson-yuan, wilson.yuan.dev@gmail.com - -## License -WSProgressHUD is available under the MIT license. See the LICENSE file for more info. - - - - - diff --git a/Demo/WSProgressHUD.xcodeproj/project.pbxproj b/Demo/WSProgressHUD.xcodeproj/project.pbxproj index 49cf38a..1f3f623 100644 --- a/Demo/WSProgressHUD.xcodeproj/project.pbxproj +++ b/Demo/WSProgressHUD.xcodeproj/project.pbxproj @@ -13,6 +13,9 @@ FE52FF281B648EDD00703FB5 /* WSIndefiniteAnimationView.m in Sources */ = {isa = PBXBuildFile; fileRef = FE52FF211B648EDD00703FB5 /* WSIndefiniteAnimationView.m */; }; FE52FF291B648EDD00703FB5 /* WSProgressBundle.bundle in Resources */ = {isa = PBXBuildFile; fileRef = FE52FF221B648EDD00703FB5 /* WSProgressBundle.bundle */; }; FE52FF2A1B648EDD00703FB5 /* WSProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = FE52FF241B648EDD00703FB5 /* WSProgressHUD.m */; }; + FE52FF2E1B649B9300703FB5 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = FE52FF2B1B649B9300703FB5 /* LICENSE */; }; + FE52FF2F1B649B9300703FB5 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = FE52FF2C1B649B9300703FB5 /* README.md */; }; + FE52FF301B649B9300703FB5 /* WSProgressHUD.podspec in Resources */ = {isa = PBXBuildFile; fileRef = FE52FF2D1B649B9300703FB5 /* WSProgressHUD.podspec */; }; FED429031B63E262002A5294 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FED428F21B63E262002A5294 /* AppDelegate.m */; }; FED429061B63E262002A5294 /* image1.jpg in Resources */ = {isa = PBXBuildFile; fileRef = FED428F71B63E262002A5294 /* image1.jpg */; }; FED429071B63E262002A5294 /* image2.png in Resources */ = {isa = PBXBuildFile; fileRef = FED428F81B63E262002A5294 /* image2.png */; }; @@ -53,6 +56,9 @@ FE52FF221B648EDD00703FB5 /* WSProgressBundle.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = WSProgressBundle.bundle; sourceTree = ""; }; FE52FF231B648EDD00703FB5 /* WSProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSProgressHUD.h; sourceTree = ""; }; FE52FF241B648EDD00703FB5 /* WSProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSProgressHUD.m; sourceTree = ""; }; + FE52FF2B1B649B9300703FB5 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; + FE52FF2C1B649B9300703FB5 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; + FE52FF2D1B649B9300703FB5 /* WSProgressHUD.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = WSProgressHUD.podspec; path = ../WSProgressHUD.podspec; sourceTree = ""; }; FED428F11B63E262002A5294 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; FED428F21B63E262002A5294 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; FED428F41B63E262002A5294 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; @@ -147,6 +153,9 @@ FEDB74921B593589003DDB79 = { isa = PBXGroup; children = ( + FE52FF2B1B649B9300703FB5 /* LICENSE */, + FE52FF2C1B649B9300703FB5 /* README.md */, + FE52FF2D1B649B9300703FB5 /* WSProgressHUD.podspec */, FE52FF171B648EDD00703FB5 /* WSProgressHUD */, FED428F01B63E262002A5294 /* WSProgressHUDDemo */, FEDB74B71B593589003DDB79 /* WSProgressHUDTests */, @@ -264,6 +273,8 @@ FED429261B63E2A0002A5294 /* LaunchScreen.xib in Resources */, FED429271B63E2A0002A5294 /* Main.storyboard in Resources */, FED429281B63E2A0002A5294 /* Info.plist in Resources */, + FE52FF2E1B649B9300703FB5 /* LICENSE in Resources */, + FE52FF301B649B9300703FB5 /* WSProgressHUD.podspec in Resources */, FED4290A1B63E262002A5294 /* Info.plist in Resources */, FED429071B63E262002A5294 /* image2.png in Resources */, FED429091B63E262002A5294 /* IMG_6584.png in Resources */, @@ -295,6 +306,7 @@ FED4290B1B63E262002A5294 /* main.m in Sources */, FE52FF271B648EDD00703FB5 /* MMMaterialDesignSpinner.m in Sources */, FE52FF281B648EDD00703FB5 /* WSIndefiniteAnimationView.m in Sources */, + FE52FF2F1B649B9300703FB5 /* README.md in Sources */, FED4290C1B63E262002A5294 /* TabViewController1.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Demo/WSProgressHUD/WSProgressHUD.m b/Demo/WSProgressHUD/WSProgressHUD.m index 3e96a6f..5c76530 100644 --- a/Demo/WSProgressHUD/WSProgressHUD.m +++ b/Demo/WSProgressHUD/WSProgressHUD.m @@ -78,7 +78,6 @@ @interface WSProgressHUD () static CGFloat const WSProgressHUDWidthEdgeOffset = 10; static CGFloat const WSProgressHUDHeightEdgeOffset = 8; static CGFloat const WSProgressHUDImageTypeWidthEdgeOffset = 30; -//static NSInteger WSProgressHUDActivityHUDCount = 0; @implementation WSProgressHUD @@ -150,7 +149,6 @@ + (void)showImage:(UIImage *)image status:(NSString *)title + (void)showImage:(UIImage *)image status:(NSString *)title maskType: (WSProgressHUDMaskType)maskType { -// [[self shareInstance] showImage:image title:title maskType:maskType]; [self showImage:image status:title maskType:maskType maskWithout:WSProgressHUDMaskWithoutDefault]; } @@ -297,7 +295,7 @@ - (void)showWithMaskType: (WSProgressHUDMaskType)maskType maskWithout: (WSProgre - (void)showWithString: (NSString *)string maskType: (WSProgressHUDMaskType)maskType maskWithout: (WSProgressHUDMaskWithoutType)withoutType { - NSAssert([NSThread mainThread], @"Show Must on main thread"); + NSAssert([NSThread isMainThread], @"Show Must on main thread"); objc_setAssociatedObject(self, @selector(maskType), @(maskType), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(hudType), @(WSProgressHUDTypeStatus), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(withoutType), @(withoutType), OBJC_ASSOCIATION_ASSIGN); @@ -314,7 +312,7 @@ - (void)showWithString: (NSString *)string maskType: (WSProgressHUDMaskType)mask - (void)showShimmeringString: (NSString *)string maskType: (WSProgressHUDMaskType)maskType maskWithout: (WSProgressHUDMaskWithoutType)withoutType { - NSAssert([NSThread mainThread], @"Show Must on main thread"); + NSAssert([NSThread isMainThread], @"Show Must on main thread"); objc_setAssociatedObject(self, @selector(maskType), @(maskType), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(hudType), @(WSProgressHUDTypeString), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(withoutType), @(withoutType), OBJC_ASSOCIATION_ASSIGN); @@ -338,7 +336,7 @@ - (void)showShimmeringString: (NSString *)string maskType: (WSProgressHUDMaskTyp - (void)showProgress:(CGFloat)progress status:(NSString*)string maskType:(WSProgressHUDMaskType)maskType maskWithout: (WSProgressHUDMaskWithoutType)withoutType { - NSAssert([NSThread mainThread], @"Show Must on main thread"); + NSAssert([NSThread isMainThread], @"Show Must on main thread"); if (self.hudIsShowing && self.hudType == WSProgressHUDTypeProgress) { self.ringLayer.strokeEnd = progress; return; @@ -361,7 +359,7 @@ - (void)showProgress:(CGFloat)progress status:(NSString*)string maskType:(WSProg - (void)showImage:(UIImage *)image status:(NSString *)title maskType: (WSProgressHUDMaskType)maskType maskWithout: (WSProgressHUDMaskWithoutType)withoutType { - NSAssert([NSThread mainThread], @"Show Must on main thread"); + NSAssert([NSThread isMainThread], @"Show Must on main thread"); objc_setAssociatedObject(self, @selector(maskType), @(maskType), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(showImage), @(1), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(hudType), @(WSProgressHUDTypeImage), OBJC_ASSOCIATION_ASSIGN); @@ -387,17 +385,20 @@ - (void)showHudViewWithAnimation { if (self.maskType != WSProgressHUDMaskTypeDefault) { - self.userInteractionEnabled = YES; - self.overlayView.userInteractionEnabled = YES; + if (self.showOnTheWindow) { + self.overlayView.userInteractionEnabled = YES; + } else { + self.userInteractionEnabled = YES; + } } else { - self.userInteractionEnabled = NO; - self.overlayView.userInteractionEnabled = NO; + if (self.showOnTheWindow) { + self.overlayView.userInteractionEnabled = NO; + } else { + self.userInteractionEnabled = NO; + } } if (self.hudView.alpha == 0) { - -// WSProgressHUDActivityHUDCount ++; -// NSLog(@"WSProgressHUDActivityHUDCount: %ld", WSProgressHUDActivityHUDCount); - + objc_setAssociatedObject(self, @selector(hudIsShowing), @(1), OBJC_ASSOCIATION_ASSIGN); self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1.2, 1.2); @@ -438,13 +439,8 @@ - (void)showHudViewWithAnimation } -- (void)dismiss //BUG: 在dismiss的时候,同一时间Show一个 +- (void)dismiss { -// WSProgressHUDActivityHUDCount -- ; -// NSLog(@"WSProgressHUDActivityHUDCount: %ld --", WSProgressHUDActivityHUDCount); -// if (WSProgressHUDActivityHUDCount != 0) { -// return; -// } if (!self.hudIsShowing || self.hudView.alpha != 1) { return; } @@ -470,7 +466,6 @@ - (void)dismiss //BUG: 在dismiss的时候,同一时间Show一个 self.userInteractionEnabled = NO; [self stopIndicatorAnimation]; [self setNeedsDisplay]; -// NSLog(@"HUD dismiss ===== isShow: %@ hudAlpha: %f, timer: %@\n\n\n", @(self.hudIsShowing), self.hudView.alpha, self.timer); }]; } @@ -487,7 +482,6 @@ - (void)stopIndicatorAnimation { - (void)addOverlayViewToWindow { if(!self.overlayView.superview){ -#if !defined(SV_APP_EXTENSIONS) NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator]; for (UIWindow *window in frontToBackWindows){ BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen; @@ -499,11 +493,6 @@ - (void)addOverlayViewToWindow break; } } -#else - if(WSProgressHUDExtensionView){ - [WSProgressHUDExtensionView addSubview:self.overlayView]; - } -#endif } else { [self.overlayView.superview bringSubviewToFront:self.overlayView]; } @@ -511,13 +500,13 @@ - (void)addOverlayViewToWindow if (!self.superview) { [self.overlayView addSubview:self]; } + + objc_setAssociatedObject(self, @selector(showOnTheWindow), @(1), OBJC_ASSOCIATION_ASSIGN); } - (void)updateSubviewsPositionWithString: (NSString *)string { -// NSLog(@"%@ bounds: %@", NSStringFromCGRect(self.frame), NSStringFromCGRect(self.bounds)); - CGSize hudSize = [self hudSizeWithString:string]; CGFloat centerX = self.frame.size.width / 2; @@ -528,7 +517,7 @@ - (void)updateSubviewsPositionWithString: (NSString *)string [self stopIndicatorAnimation]; } else { self.hudView.bounds = hudBounds; - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect;//Reset the view frame self.hudView.center = CGPointMake(centerX, centerY); CGFloat hudCenterX = CGRectGetWidth(hudBounds)/2; @@ -540,7 +529,7 @@ - (void)updateSubviewsPositionWithString: (NSString *)string [self startIndicatorAnimation:YES]; if (string) { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); self.spinnerView.center = self.indefiniteAnimationView.center = self.indicatorView.center = CGPointMake(15, hudCenterY); @@ -551,11 +540,11 @@ - (void)updateSubviewsPositionWithString: (NSString *)string }break; case WSProgressHUDTypeString: { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); - self.shimmeringView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.shimmeringView.frame = WSProgressHUDStringRect; [self setShimmeringLabelSize:WSProgressHUDStringRect.size]; self.shimmeringView.center = CGPointMake(hudCenterX, hudCenterY); @@ -565,7 +554,7 @@ - (void)updateSubviewsPositionWithString: (NSString *)string case WSProgressHUDTypeProgress: { if (string) { self.ringLayer.position = self.backgroundRingLayer.position = CGPointMake(15, hudCenterY); - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); } else { self.ringLayer.position = self.backgroundRingLayer.position = CGPointMake(hudCenterX, hudCenterY); @@ -735,7 +724,7 @@ - (void)updateSubview [self startIndicatorAnimation:YES]; if (self.labelView.text) { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.spinnerView.center = self.indefiniteAnimationView.center = self.indicatorView.center = CGPointMake(15, hudCenterY); self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); @@ -747,7 +736,7 @@ - (void)updateSubview }break; case WSProgressHUDTypeString: { - self.shimmeringView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.shimmeringView.frame = WSProgressHUDStringRect; [self setShimmeringLabelSize:WSProgressHUDStringRect.size]; self.shimmeringView.center = CGPointMake(hudCenterX, hudCenterY); @@ -756,7 +745,7 @@ - (void)updateSubview }break; case WSProgressHUDTypeProgress: { if (self.labelView.text) { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.ringLayer.position = self.backgroundRingLayer.position = CGPointMake(15, hudCenterY); self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); } else { @@ -764,7 +753,7 @@ - (void)updateSubview } }break; case WSProgressHUDTypeImage: { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; if (self.imageView.image) { WSProgressHUDStringRect.origin.y = imageOffset; [self startIndicatorAnimation:NO]; @@ -863,7 +852,7 @@ - (void)setMaskEdgeWithType: (WSProgressHUDMaskType)maskType }break; case WSProgressHUDMaskWithoutNavigation: { maskBottomEdge = 0; - maskTopEdge = 64; //判断StatusBarHidden + maskTopEdge = 64; }break; case WSProgressHUDMaskWithoutTabbar: { maskBottomEdge = 0; @@ -883,9 +872,11 @@ - (void)setMaskEdgeWithType: (WSProgressHUDMaskType)maskType } self.overlayView.frame = CGRectMake(0, maskTopEdge, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - maskTopEdge - maskBottomEdge); - CGRect rect = self.frame; - rect.size = self.overlayView.frame.size; - self.frame = rect; + if (self.showOnTheWindow) { + CGRect rect = self.frame; + rect.size = self.overlayView.frame.size; + self.frame = rect; + } } @@ -910,10 +901,6 @@ - (void)invalidateTimer if (self.timer) { [_timer invalidate]; _timer = nil; -// NSLog(@"timer be set nil: %@", self.timer); - } else { -// NSLog(@"timer is nil"); - } } - (void)setTimer:(NSTimer *)timer @@ -940,7 +927,6 @@ - (CGFloat)shimmingSpeedWithString: (NSString *)string - (CGFloat)visibleKeyboardHeight { -#if !defined(SV_APP_EXTENSIONS) UIWindow *keyboardWindow = nil; for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) { if(![[testWindow class] isEqual:[UIWindow class]]) { @@ -960,7 +946,6 @@ - (CGFloat)visibleKeyboardHeight { } } } -#endif return 0; } @@ -991,8 +976,7 @@ - (void)setProgressHUDIndicatorStyle: (WSProgressHUDIndicatorStyle)style { objc_setAssociatedObject(self, @selector(indicatorStyle), @(style), OBJC_ASSOCIATION_ASSIGN); } - -#pragma mark - Super Method +#pragma mark - Draw rect - (void)drawRect:(CGRect)rect { switch (self.maskType) { @@ -1048,11 +1032,9 @@ - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { -// NSLog(@"%@", NSStringFromCGRect(self.bounds)); WSProgressHUDForeGroundColor = [UIColor whiteColor]; WSProgressHUDBackGroundColor = [UIColor colorWithWhite:0.3 alpha:1]; -// WSProgressHUDActivityHUDCount = 0; NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSURL *bundleUrl = [bundle URLForResource:@"WSProgressBundle" withExtension:@"bundle"]; @@ -1078,15 +1060,11 @@ - (instancetype)initWithFrame:(CGRect)frame [self.hudView addSubview:self.imageView]; [self.hudView addSubview:self.spinnerView]; -// [self.hudView.layer addSublayer:self.ringLayer]; -// [self.hudView.layer addSublayer:self.backgroundRingLayer]; - self.shimmeringView.contentView = self.shimmeringLabel; self.backgroundColor = [UIColor clearColor]; self.userInteractionEnabled = NO; -// self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } return self; } @@ -1168,7 +1146,6 @@ - (UIControl *)overlayView { _overlayView = [[UIControl alloc] initWithFrame:windowBounds]; _overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _overlayView.backgroundColor = [UIColor clearColor]; -// [_overlayView addTarget:self action:@selector(overlayViewDidReceiveTouchEvent:forEvent:) forControlEvents:UIControlEventTouchDown]; } return _overlayView; } @@ -1209,26 +1186,6 @@ - (MMMaterialDesignSpinner *)spinnerView return _spinnerView; } -//- (CAShapeLayer *)ringLayer -//{ -// if (!_ringLayer) { -// CGPoint center = CGPointMake(CGRectGetWidth(_hudView.frame)/2, CGRectGetHeight(_hudView.frame)/2); -// -// _ringLayer = [self createRingLayerWithCenter:center radius:WSProgressHUDIndicatorSmall lineWidth:1 color:WSProgressHUDForeGroundColor]; -// } -// return _ringLayer; -//} -// -//- (CAShapeLayer *)backgroundRingLayer -//{ -// if (!_backgroundRingLayer) { -// CGPoint center = CGPointMake(CGRectGetWidth(_hudView.frame)/2, CGRectGetHeight(_hudView.frame)/2); -// _backgroundRingLayer = [self createRingLayerWithCenter:center radius:WSProgressHUDIndicatorSmall lineWidth:1 color:WSProgressHUDBackGroundColor]; -// _backgroundRingLayer.strokeEnd = 1; -// } -// return _backgroundRingLayer; -//} - - (BOOL)onlyShowTitle { return [objc_getAssociatedObject(self, _cmd) boolValue]; @@ -1260,6 +1217,10 @@ - (BOOL)hudIsShowing - (WSProgressHUDIndicatorStyle )indicatorStyle { return [objc_getAssociatedObject(self, _cmd) integerValue]; } +- (BOOL)showOnTheWindow +{ + return [objc_getAssociatedObject(self, _cmd) boolValue]; +} diff --git a/Demo/WSProgressHUDDemo/ViewController.m b/Demo/WSProgressHUDDemo/ViewController.m index 6ad2816..9010677 100644 --- a/Demo/WSProgressHUDDemo/ViewController.m +++ b/Demo/WSProgressHUDDemo/ViewController.m @@ -32,7 +32,7 @@ - (void)viewDidLoad { //show [hud showWithString:@"Wating..." maskType:WSProgressHUDMaskTypeBlack]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [hud dismiss]; }); diff --git a/README.md b/README.md index 616ab41..8d9302b 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ This is a beauful hud view for iPhone & iPad [![License](https://img.shields.io/cocoapods/l/WSProgressHUD.svg?style=flat)](http://cocoapods.org/pods/WSProgressHUD) [![Platform](https://img.shields.io/cocoapods/p/WSProgressHUD.svg?style=flat)](http://cocoapods.org/pods/WSProgressHUD) + ![Demo](https://raw.githubusercontent.com/devSC/WSProgressHUD/master/Demo/Demo.gif) #Usage -To run the WSProgressHUD project +To Download the project. Run the WSProgressHUD.xcodeproj in the demo directory. ``` objc //Show on the self.view @@ -62,6 +63,10 @@ To run the WSProgressHUD project //Dismiss [WSProgressHUD dismiss]; + + //And There have 3 indicator style for your choice + [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorSmall] //small custom spinner + ``` ## Installation diff --git a/WSProgressHUD.podspec b/WSProgressHUD.podspec index 41ea363..5ba8c84 100644 --- a/WSProgressHUD.podspec +++ b/WSProgressHUD.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "WSProgressHUD" - s.version = "1.0.4" + s.version = "1.0.5" s.summary = "WSProgressHUD is a beauful hud view for iPhone & iPad." s.description = <<-DESC @@ -34,7 +34,7 @@ Pod::Spec.new do |s| s.author = { "袁仕崇" => "xiaochong2154@163.com" } s.platform = :ios, "6.0" - s.source = { :git => "https://github.com/devSC/WSProgressHUD.git", :tag => "1.0.4" } + s.source = { :git => "https://github.com/devSC/WSProgressHUD.git", :tag => "1.0.5" } s.source_files = "WSProgressHUD/*" s.exclude_files = "Demo/Exclude" diff --git a/WSProgressHUD/WSProgressHUD.m b/WSProgressHUD/WSProgressHUD.m index 3e96a6f..92155f0 100644 --- a/WSProgressHUD/WSProgressHUD.m +++ b/WSProgressHUD/WSProgressHUD.m @@ -78,7 +78,6 @@ @interface WSProgressHUD () static CGFloat const WSProgressHUDWidthEdgeOffset = 10; static CGFloat const WSProgressHUDHeightEdgeOffset = 8; static CGFloat const WSProgressHUDImageTypeWidthEdgeOffset = 30; -//static NSInteger WSProgressHUDActivityHUDCount = 0; @implementation WSProgressHUD @@ -150,7 +149,6 @@ + (void)showImage:(UIImage *)image status:(NSString *)title + (void)showImage:(UIImage *)image status:(NSString *)title maskType: (WSProgressHUDMaskType)maskType { -// [[self shareInstance] showImage:image title:title maskType:maskType]; [self showImage:image status:title maskType:maskType maskWithout:WSProgressHUDMaskWithoutDefault]; } @@ -297,7 +295,7 @@ - (void)showWithMaskType: (WSProgressHUDMaskType)maskType maskWithout: (WSProgre - (void)showWithString: (NSString *)string maskType: (WSProgressHUDMaskType)maskType maskWithout: (WSProgressHUDMaskWithoutType)withoutType { - NSAssert([NSThread mainThread], @"Show Must on main thread"); + NSAssert([NSThread isMainThread], @"Show Must on main thread"); objc_setAssociatedObject(self, @selector(maskType), @(maskType), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(hudType), @(WSProgressHUDTypeStatus), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(withoutType), @(withoutType), OBJC_ASSOCIATION_ASSIGN); @@ -314,7 +312,7 @@ - (void)showWithString: (NSString *)string maskType: (WSProgressHUDMaskType)mask - (void)showShimmeringString: (NSString *)string maskType: (WSProgressHUDMaskType)maskType maskWithout: (WSProgressHUDMaskWithoutType)withoutType { - NSAssert([NSThread mainThread], @"Show Must on main thread"); + NSAssert([NSThread isMainThread], @"Show Must on main thread"); objc_setAssociatedObject(self, @selector(maskType), @(maskType), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(hudType), @(WSProgressHUDTypeString), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(withoutType), @(withoutType), OBJC_ASSOCIATION_ASSIGN); @@ -338,7 +336,7 @@ - (void)showShimmeringString: (NSString *)string maskType: (WSProgressHUDMaskTyp - (void)showProgress:(CGFloat)progress status:(NSString*)string maskType:(WSProgressHUDMaskType)maskType maskWithout: (WSProgressHUDMaskWithoutType)withoutType { - NSAssert([NSThread mainThread], @"Show Must on main thread"); + NSAssert([NSThread isMainThread], @"Show Must on main thread"); if (self.hudIsShowing && self.hudType == WSProgressHUDTypeProgress) { self.ringLayer.strokeEnd = progress; return; @@ -351,7 +349,6 @@ - (void)showProgress:(CGFloat)progress status:(NSString*)string maskType:(WSProg [self setMaskEdgeWithType:self.maskType]; - [self updateSubviewsPositionWithString:string]; [self showHudViewWithAnimation]; @@ -361,7 +358,7 @@ - (void)showProgress:(CGFloat)progress status:(NSString*)string maskType:(WSProg - (void)showImage:(UIImage *)image status:(NSString *)title maskType: (WSProgressHUDMaskType)maskType maskWithout: (WSProgressHUDMaskWithoutType)withoutType { - NSAssert([NSThread mainThread], @"Show Must on main thread"); + NSAssert([NSThread isMainThread], @"Show Must on main thread"); objc_setAssociatedObject(self, @selector(maskType), @(maskType), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(showImage), @(1), OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(self, @selector(hudType), @(WSProgressHUDTypeImage), OBJC_ASSOCIATION_ASSIGN); @@ -387,17 +384,20 @@ - (void)showHudViewWithAnimation { if (self.maskType != WSProgressHUDMaskTypeDefault) { - self.userInteractionEnabled = YES; - self.overlayView.userInteractionEnabled = YES; + if (self.showOnTheWindow) { + self.overlayView.userInteractionEnabled = YES; + } else { + self.userInteractionEnabled = YES; + } } else { - self.userInteractionEnabled = NO; - self.overlayView.userInteractionEnabled = NO; + if (self.showOnTheWindow) { + self.overlayView.userInteractionEnabled = NO; + } else { + self.userInteractionEnabled = NO; + } } if (self.hudView.alpha == 0) { - -// WSProgressHUDActivityHUDCount ++; -// NSLog(@"WSProgressHUDActivityHUDCount: %ld", WSProgressHUDActivityHUDCount); - + objc_setAssociatedObject(self, @selector(hudIsShowing), @(1), OBJC_ASSOCIATION_ASSIGN); self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1.2, 1.2); @@ -438,13 +438,8 @@ - (void)showHudViewWithAnimation } -- (void)dismiss //BUG: 在dismiss的时候,同一时间Show一个 +- (void)dismiss { -// WSProgressHUDActivityHUDCount -- ; -// NSLog(@"WSProgressHUDActivityHUDCount: %ld --", WSProgressHUDActivityHUDCount); -// if (WSProgressHUDActivityHUDCount != 0) { -// return; -// } if (!self.hudIsShowing || self.hudView.alpha != 1) { return; } @@ -470,7 +465,6 @@ - (void)dismiss //BUG: 在dismiss的时候,同一时间Show一个 self.userInteractionEnabled = NO; [self stopIndicatorAnimation]; [self setNeedsDisplay]; -// NSLog(@"HUD dismiss ===== isShow: %@ hudAlpha: %f, timer: %@\n\n\n", @(self.hudIsShowing), self.hudView.alpha, self.timer); }]; } @@ -487,7 +481,6 @@ - (void)stopIndicatorAnimation { - (void)addOverlayViewToWindow { if(!self.overlayView.superview){ -#if !defined(SV_APP_EXTENSIONS) NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator]; for (UIWindow *window in frontToBackWindows){ BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen; @@ -499,11 +492,6 @@ - (void)addOverlayViewToWindow break; } } -#else - if(WSProgressHUDExtensionView){ - [WSProgressHUDExtensionView addSubview:self.overlayView]; - } -#endif } else { [self.overlayView.superview bringSubviewToFront:self.overlayView]; } @@ -511,13 +499,13 @@ - (void)addOverlayViewToWindow if (!self.superview) { [self.overlayView addSubview:self]; } + + objc_setAssociatedObject(self, @selector(showOnTheWindow), @(1), OBJC_ASSOCIATION_ASSIGN); } - (void)updateSubviewsPositionWithString: (NSString *)string { -// NSLog(@"%@ bounds: %@", NSStringFromCGRect(self.frame), NSStringFromCGRect(self.bounds)); - CGSize hudSize = [self hudSizeWithString:string]; CGFloat centerX = self.frame.size.width / 2; @@ -528,7 +516,7 @@ - (void)updateSubviewsPositionWithString: (NSString *)string [self stopIndicatorAnimation]; } else { self.hudView.bounds = hudBounds; - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect;//Reset the view frame self.hudView.center = CGPointMake(centerX, centerY); CGFloat hudCenterX = CGRectGetWidth(hudBounds)/2; @@ -540,7 +528,7 @@ - (void)updateSubviewsPositionWithString: (NSString *)string [self startIndicatorAnimation:YES]; if (string) { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); self.spinnerView.center = self.indefiniteAnimationView.center = self.indicatorView.center = CGPointMake(15, hudCenterY); @@ -551,11 +539,11 @@ - (void)updateSubviewsPositionWithString: (NSString *)string }break; case WSProgressHUDTypeString: { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); - self.shimmeringView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.shimmeringView.frame = WSProgressHUDStringRect; [self setShimmeringLabelSize:WSProgressHUDStringRect.size]; self.shimmeringView.center = CGPointMake(hudCenterX, hudCenterY); @@ -565,7 +553,7 @@ - (void)updateSubviewsPositionWithString: (NSString *)string case WSProgressHUDTypeProgress: { if (string) { self.ringLayer.position = self.backgroundRingLayer.position = CGPointMake(15, hudCenterY); - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); } else { self.ringLayer.position = self.backgroundRingLayer.position = CGPointMake(hudCenterX, hudCenterY); @@ -735,7 +723,7 @@ - (void)updateSubview [self startIndicatorAnimation:YES]; if (self.labelView.text) { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.spinnerView.center = self.indefiniteAnimationView.center = self.indicatorView.center = CGPointMake(15, hudCenterY); self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); @@ -747,7 +735,7 @@ - (void)updateSubview }break; case WSProgressHUDTypeString: { - self.shimmeringView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.shimmeringView.frame = WSProgressHUDStringRect; [self setShimmeringLabelSize:WSProgressHUDStringRect.size]; self.shimmeringView.center = CGPointMake(hudCenterX, hudCenterY); @@ -756,7 +744,7 @@ - (void)updateSubview }break; case WSProgressHUDTypeProgress: { if (self.labelView.text) { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; self.ringLayer.position = self.backgroundRingLayer.position = CGPointMake(15, hudCenterY); self.labelView.center = CGPointMake(hudCenterX + 10, hudCenterY); } else { @@ -764,7 +752,7 @@ - (void)updateSubview } }break; case WSProgressHUDTypeImage: { - self.labelView.frame = WSProgressHUDStringRect;//设置完hud的frame后需要重新设置 + self.labelView.frame = WSProgressHUDStringRect; if (self.imageView.image) { WSProgressHUDStringRect.origin.y = imageOffset; [self startIndicatorAnimation:NO]; @@ -863,7 +851,7 @@ - (void)setMaskEdgeWithType: (WSProgressHUDMaskType)maskType }break; case WSProgressHUDMaskWithoutNavigation: { maskBottomEdge = 0; - maskTopEdge = 64; //判断StatusBarHidden + maskTopEdge = 64; }break; case WSProgressHUDMaskWithoutTabbar: { maskBottomEdge = 0; @@ -883,9 +871,11 @@ - (void)setMaskEdgeWithType: (WSProgressHUDMaskType)maskType } self.overlayView.frame = CGRectMake(0, maskTopEdge, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - maskTopEdge - maskBottomEdge); - CGRect rect = self.frame; - rect.size = self.overlayView.frame.size; - self.frame = rect; + if (self.showOnTheWindow) { + CGRect rect = self.frame; + rect.size = self.overlayView.frame.size; + self.frame = rect; + } } @@ -910,10 +900,6 @@ - (void)invalidateTimer if (self.timer) { [_timer invalidate]; _timer = nil; -// NSLog(@"timer be set nil: %@", self.timer); - } else { -// NSLog(@"timer is nil"); - } } - (void)setTimer:(NSTimer *)timer @@ -940,7 +926,6 @@ - (CGFloat)shimmingSpeedWithString: (NSString *)string - (CGFloat)visibleKeyboardHeight { -#if !defined(SV_APP_EXTENSIONS) UIWindow *keyboardWindow = nil; for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) { if(![[testWindow class] isEqual:[UIWindow class]]) { @@ -960,7 +945,6 @@ - (CGFloat)visibleKeyboardHeight { } } } -#endif return 0; } @@ -991,8 +975,7 @@ - (void)setProgressHUDIndicatorStyle: (WSProgressHUDIndicatorStyle)style { objc_setAssociatedObject(self, @selector(indicatorStyle), @(style), OBJC_ASSOCIATION_ASSIGN); } - -#pragma mark - Super Method +#pragma mark - Draw rect - (void)drawRect:(CGRect)rect { switch (self.maskType) { @@ -1048,11 +1031,9 @@ - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { -// NSLog(@"%@", NSStringFromCGRect(self.bounds)); WSProgressHUDForeGroundColor = [UIColor whiteColor]; WSProgressHUDBackGroundColor = [UIColor colorWithWhite:0.3 alpha:1]; -// WSProgressHUDActivityHUDCount = 0; NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSURL *bundleUrl = [bundle URLForResource:@"WSProgressBundle" withExtension:@"bundle"]; @@ -1078,15 +1059,11 @@ - (instancetype)initWithFrame:(CGRect)frame [self.hudView addSubview:self.imageView]; [self.hudView addSubview:self.spinnerView]; -// [self.hudView.layer addSublayer:self.ringLayer]; -// [self.hudView.layer addSublayer:self.backgroundRingLayer]; - self.shimmeringView.contentView = self.shimmeringLabel; self.backgroundColor = [UIColor clearColor]; self.userInteractionEnabled = NO; -// self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } return self; } @@ -1168,7 +1145,6 @@ - (UIControl *)overlayView { _overlayView = [[UIControl alloc] initWithFrame:windowBounds]; _overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _overlayView.backgroundColor = [UIColor clearColor]; -// [_overlayView addTarget:self action:@selector(overlayViewDidReceiveTouchEvent:forEvent:) forControlEvents:UIControlEventTouchDown]; } return _overlayView; } @@ -1209,26 +1185,6 @@ - (MMMaterialDesignSpinner *)spinnerView return _spinnerView; } -//- (CAShapeLayer *)ringLayer -//{ -// if (!_ringLayer) { -// CGPoint center = CGPointMake(CGRectGetWidth(_hudView.frame)/2, CGRectGetHeight(_hudView.frame)/2); -// -// _ringLayer = [self createRingLayerWithCenter:center radius:WSProgressHUDIndicatorSmall lineWidth:1 color:WSProgressHUDForeGroundColor]; -// } -// return _ringLayer; -//} -// -//- (CAShapeLayer *)backgroundRingLayer -//{ -// if (!_backgroundRingLayer) { -// CGPoint center = CGPointMake(CGRectGetWidth(_hudView.frame)/2, CGRectGetHeight(_hudView.frame)/2); -// _backgroundRingLayer = [self createRingLayerWithCenter:center radius:WSProgressHUDIndicatorSmall lineWidth:1 color:WSProgressHUDBackGroundColor]; -// _backgroundRingLayer.strokeEnd = 1; -// } -// return _backgroundRingLayer; -//} - - (BOOL)onlyShowTitle { return [objc_getAssociatedObject(self, _cmd) boolValue]; @@ -1260,6 +1216,10 @@ - (BOOL)hudIsShowing - (WSProgressHUDIndicatorStyle )indicatorStyle { return [objc_getAssociatedObject(self, _cmd) integerValue]; } +- (BOOL)showOnTheWindow +{ + return [objc_getAssociatedObject(self, _cmd) boolValue]; +}