As I understand it, the newly created UIWindow does not rotate automatically when the orientation changes. I do not know if this is new for iOS 8 or if it is a mistake, but I was able to overcome this problem with the following code snippet:
UIWindow *window=[UIApplication sharedApplication].keyWindow; self.progressWindow = [[UIWindow alloc] initWithFrame:window.frame]; self.progressWindow.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f]; self.progressWindow.windowLevel = UIWindowLevelAlert; [self handleOrientationChange]; [self.progressWindow makeKeyAndVisible]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOrientationChange) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
The implementation for handleOrientationChange is as follows:
#define DegreesToRadians(degrees) (degrees * M_PI / 180) - (void)handleOrientationChange { if (self.progressWindow) { // rotate the UIWindow manually UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; [self.progressWindow setTransform:[self transformForOrientation:orientation]]; // resize the UIWindow according to the new screen size if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]) { // iOS 8 CGRect screenRect = [UIScreen mainScreen].nativeBounds; CGRect progressWindowFrame = self.progressWindow.frame; progressWindowFrame.origin.x = 0; progressWindowFrame.origin.y = 0; progressWindowFrame.size.width = screenRect.size.width / [UIScreen mainScreen].nativeScale; progressWindowFrame.size.height = screenRect.size.height / [UIScreen mainScreen].nativeScale; self.progressWindow.frame = progressWindowFrame; } else { // iOs 7 or below CGRect screenRect = [UIScreen mainScreen].bounds; CGRect progressWindowFrame = self.progressWindow.frame; progressWindowFrame.origin.x = 0; progressWindowFrame.origin.y = 0; progressWindowFrame.size.width = screenRect.size.width; progressWindowFrame.size.height = screenRect.size.height; self.progressWindow.frame = progressWindowFrame; } } } - (CGAffineTransform)transformForOrientation:(UIInterfaceOrientation)orientation { switch (orientation) { case UIInterfaceOrientationLandscapeLeft: return CGAffineTransformMakeRotation(-DegreesToRadians(90)); case UIInterfaceOrientationLandscapeRight: return CGAffineTransformMakeRotation(DegreesToRadians(90)); case UIInterfaceOrientationPortraitUpsideDown: return CGAffineTransformMakeRotation(DegreesToRadians(180)); case UIInterfaceOrientationPortrait: default: return CGAffineTransformMakeRotation(DegreesToRadians(0)); } }
I got the idea from the accepted answer of this question.
source share