diff --git a/Classes/HUD/M13ProgressHUD.h b/Classes/HUD/M13ProgressHUD.h index 335ad41..04c0fb0 100644 --- a/Classes/HUD/M13ProgressHUD.h +++ b/Classes/HUD/M13ProgressHUD.h @@ -87,6 +87,12 @@ typedef enum { @property (nonatomic, assign) BOOL dismissAfterAction; /**Wether or not the HUD is currenty visible.*/ - (BOOL)isVisible; +/**Wether or not the HUD will auto rotate to the device orientation. + @note If set to `YES`, The HUD will rotate automatically to the device orientation, regardless of the interface orientation. This setting is suggested if the displayed view controller rotates and the HUD is displayed in a UIWindow. If the HUD is contained in a UIViewController. This setting should be set to NO, and the rotation should be set manually via the rotation property. + */ +@property (nonatomic, assign) BOOL shouldAutorotate; +/**The orientation of the HUD.*/ +@property (nonatomic, assign) UIInterfaceOrientation orientation; /**@name Actions*/ /**Set the progress of the `M13ProgressView`. @@ -101,6 +107,7 @@ typedef enum { @param animated Wether or not to animate the change*/ - (void)show:(BOOL)animated; /**Hide the progress HUD. + @note This method should be used when the HUD is going to be reused. When the HUD needs to be shown again, use `show:` do not initalize another instance. That will cause a memory leak. If the HUD is not going to be reused, use `dismiss:` instead. To retreive a hidden HUD, either hold onto it with a global variable, or use the `progressHUD` method for UIView. @param animated Wether or not to animate the change*/ - (void)hide:(BOOL)animated; /**Dismiss the progress HUD and remove it from its superview. diff --git a/Classes/HUD/M13ProgressHUD.m b/Classes/HUD/M13ProgressHUD.m index 3c9a888..61c7032 100644 --- a/Classes/HUD/M13ProgressHUD.m +++ b/Classes/HUD/M13ProgressHUD.m @@ -76,6 +76,7 @@ - (void)setup _secondaryColor = [UIColor colorWithRed:181/255.0 green:182/255.0 blue:183/255.0 alpha:1.0]; _progress = 0; _indeterminate = NO; + _shouldAutorotate = YES; if (self.frame.size.height != 0 && self.frame.size.width != 0) { _progressViewSize = CGSizeMake(150 / 4, 150 / 4); } @@ -278,6 +279,7 @@ - (void)performAction:(M13ProgressViewAction)action animated:(BOOL)animated - (void)show:(BOOL)animated { //reset the blurs to the curent screen if need be + [self registerForNotificationCenter]; [self setNeedsLayout]; [self setNeedsDisplay]; @@ -309,6 +311,8 @@ - (void)show:(BOOL)animated - (void)hide:(BOOL)animated { + [self unregisterFromNotificationCenter]; + CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeAnimation.fromValue = [NSNumber numberWithFloat:1.0]; fadeAnimation.toValue = [NSNumber numberWithFloat:0.0]; @@ -342,6 +346,9 @@ - (void)hide:(BOOL)animated - (void)dismiss:(BOOL)animated { [self hide:animated]; + + //Removes the HUD from the superview, dismissing it. + [self performSelector:@selector(removeFromSuperview) withObject:Nil afterDelay:_animationDuration]; } #pragma mark - Notifications @@ -357,11 +364,23 @@ - (void)unregisterFromNotificationCenter { } - (void)deviceOrientationDidChange:(NSNotification *)notification { - dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)); - dispatch_after(popTime, dispatch_get_main_queue(), ^{ - [self setNeedsLayout]; - [self setNeedsDisplay]; - }); + if (_shouldAutorotate) { + UIDeviceOrientation deviceOrientation = [notification.object orientation]; + if (UIDeviceOrientationIsPortrait(deviceOrientation)) { + if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown) { + _orientation = UIInterfaceOrientationPortraitUpsideDown; + } else { + _orientation = UIInterfaceOrientationPortrait; + } + } else { + if (deviceOrientation == UIDeviceOrientationLandscapeLeft) { + _orientation = UIInterfaceOrientationLandscapeLeft; + } else { + _orientation = UIInterfaceOrientationLandscapeRight; + } + } + [self layoutHUD]; + } } #pragma mark Layout @@ -502,10 +521,19 @@ - (void)layoutHUD statusRect.size.height = 0.0; } + //Swap height and with on rotation + if (_orientation == UIInterfaceOrientationLandscapeLeft || _orientation == UIInterfaceOrientationLandscapeRight) { + //Flip the width and height. + CGFloat temp = backgroundRect.size.width; + backgroundRect.size.width = backgroundRect.size.height; + backgroundRect.size.height = temp; + } + //Set the frame of the background and its subviews [UIView animateWithDuration:_animationDuration animations:^{ backgroundView.frame = CGRectIntegral(backgroundRect); _progressView.frame = CGRectIntegral(progressRect); + backgroundView.transform = CGAffineTransformMakeRotation([self angleForDeviceOrientation]); //Fade the label statusLabel.alpha = 0.0; } completion:^(BOOL finished) { @@ -712,12 +740,11 @@ - (UIImage *)snapshotForBlurredBackgroundInView:(UIView *)view - (CGFloat)angleForDeviceOrientation { - UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation; - if (orientation == UIInterfaceOrientationLandscapeLeft) { - return -M_PI_2; - } else if (orientation == UIInterfaceOrientationLandscapeRight) { + if (_orientation == UIInterfaceOrientationLandscapeLeft) { return M_PI_2; - } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) { + } else if (_orientation == UIInterfaceOrientationLandscapeRight) { + return -M_PI_2; + } else if (_orientation == UIInterfaceOrientationPortraitUpsideDown) { return M_PI; } return 0; diff --git a/Documentation/docset-installed.txt b/Documentation/docset-installed.txt index a829b20..a703e5b 100644 --- a/Documentation/docset-installed.txt +++ b/Documentation/docset-installed.txt @@ -1,4 +1,4 @@ Documentation set was installed to Xcode! Path: /Users/Brandon/Library/Developer/Shared/Documentation/DocSets/com.BrandonMcQuilkin.M13ProgressSuite.docset -Time: 2014-01-17 16:58:14 +0000 \ No newline at end of file +Time: 2014-02-19 14:59:02 +0000 \ No newline at end of file diff --git a/Documentation/docset/Contents/Resources/Documents/Categories/UINavigationController+M13ProgressViewBar.html b/Documentation/docset/Contents/Resources/Documents/Categories/UINavigationController+M13ProgressViewBar.html index 6e54f8d..af898f7 100644 --- a/Documentation/docset/Contents/Resources/Documents/Categories/UINavigationController+M13ProgressViewBar.html +++ b/Documentation/docset/Contents/Resources/Documents/Categories/UINavigationController+M13ProgressViewBar.html @@ -466,7 +466,7 @@

Declared In