Skip to content

Commit

Permalink
Merge branch 'od/issue_71' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Jul 23, 2014
2 parents 5325fa7 + e3feef0 commit a413964
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
8 changes: 1 addition & 7 deletions Core/Source/iOS/DTProgressHUD/DTProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,7 @@ - (void)_prepareForReuse
if (!_hudWindow)
{
// use own window
_hudWindow = [[DTProgressHUDWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_hudWindow.windowLevel = UIWindowLevelAlert;
_hudWindow.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_hudWindow.autoresizesSubviews = NO;
_hudWindow.userInteractionEnabled = NO;

[_hudWindow addSubview:self];
_hudWindow = [[DTProgressHUDWindow alloc] initWithProgressHUD:self];
[_hudWindow makeKeyAndVisible];
}

Expand Down
8 changes: 7 additions & 1 deletion Core/Source/iOS/DTProgressHUD/DTProgressHUDWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
// Copyright (c) 2014 Cocoanetics. All rights reserved.
//

#import <UIKit/UIKit.h>
@class DTProgressHUD;

/**
Class for correcting rotations when using UIWindow in iOS
*/
@interface DTProgressHUDWindow : UIWindow

/**
Designated initializer. Sets the passed DTProgressHUD view as root view
@param progressHUD The DTProgressHUD instance to set as root view
*/
- (instancetype)initWithProgressHUD:(DTProgressHUD *)progressHUD;

@end
43 changes: 22 additions & 21 deletions Core/Source/iOS/DTProgressHUD/DTProgressHUDWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "DTProgressHUDWindow.h"
#import "DTProgressHUD.h"

#define DegreesToRadians(degrees) (degrees * M_PI / 180)

Expand Down Expand Up @@ -37,41 +38,41 @@ static CGAffineTransform _transformForInterfaceOrientation(UIInterfaceOrientatio

@implementation DTProgressHUDWindow

- (instancetype)initWithFrame:(CGRect)frame
- (instancetype)initWithProgressHUD:(DTProgressHUD *)progressHUD
{
self = [super initWithFrame:frame];
NSParameterAssert(progressHUD);

if (self)
{
[self _setup];
}
return self;
}

- (instancetype)init
{
self = [super init];
self = [super initWithFrame:[UIScreen mainScreen].bounds];

if (self)
{
[self _setup];
self.windowLevel = UIWindowLevelAlert;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.autoresizesSubviews = NO;
self.userInteractionEnabled = NO;

// use a dummy view controller to calm iOS 7's warning about missing root VC
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view = progressHUD;
self.rootViewController = viewController; // this replaces the addSubview

// observe interface rotations
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarDidChangeFrame:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

// set initial transform
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self setTransform:_transformForInterfaceOrientation(orientation)];
}
return self;
}

- (void)_setup
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarDidChangeFrame:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self setTransform:_transformForInterfaceOrientation(orientation)];
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Notifications

- (void)statusBarDidChangeFrame:(NSNotification *)notification
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
Expand Down

0 comments on commit a413964

Please sign in to comment.