Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orientation changes broken on iOS9 + Launch Screen Storyboard #89

Open
gmondada opened this issue Oct 5, 2015 · 5 comments
Open

Orientation changes broken on iOS9 + Launch Screen Storyboard #89

gmondada opened this issue Oct 5, 2015 · 5 comments

Comments

@gmondada
Copy link

gmondada commented Oct 5, 2015

If you take the CustomIOSAlertView demo app, add a launch screen storyboard and run in the iPad Air iOS9 simulator, device rotations are not working anymore.
The problem comes from [UIScreen mainScreen].bounds.size returning the size of the screen before the orientation change.
This is a very strange problem not happing, for instance, on iPad 2 iOS8.4 and iPhone 5 iOS9.0.2.
Seen on the simulator but also on a real iPad Air 1. It doesn't depend on the Deployment Target.
Tested on Xcode 7.0.1.

@timeflying
Copy link

timeflying commented May 26, 2017

2 years past, the bug still there on iOS 10

  1. First on Portrait view ( Fine )
    simulator screen shot 26 may 2017 2 48 20 pm

  2. Rotate to landscape
    simulator screen shot 26 may 2017 2 48 26 pm

  3. Rotate back to portrait
    simulator screen shot 26 may 2017 2 48 30 pm

No one want to solve this bug?

@rayalarajee
Copy link

Did you got soultion for this i am facing same issue

@kemalserkan
Copy link

@rayalarajee
Try to look and solve as soon as possible time.

@rayalarajee
Copy link

Could you please let me know if you found soultion @kemalserkan @timeflying

@andymedvedev
Copy link

@rayalarajee @timeflying Hey there!
I Don't know why but when orientation changes screen size remains previous.

Here is the solution or fix:

- (void)changeOrientationForIOS8: (NSNotification *)notification {
    
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
    UIDevice  *device = notification.object;
    
    CGFloat minDim = MIN(screenWidth, screenHeight);
    CGFloat maxDim = MAX(screenWidth, screenHeight);
    
    switch (device.orientation)
    {
            case UIDeviceOrientationPortrait:
            screenWidth = minDim;
            screenHeight = maxDim;
            break;
            
            case UIDeviceOrientationLandscapeLeft:
            screenWidth = maxDim;
            screenHeight = minDim;
            break;
            
            case UIDeviceOrientationLandscapeRight:
            screenWidth = maxDim;
            screenHeight = minDim;
            break;
            
            case UIDeviceOrientationPortraitUpsideDown:
            screenWidth = minDim;
            screenHeight = maxDim;
            break;
            
            default:
            break;
    }
    
    [UIView animateWithDuration:0.2f delay:0.0 options:UIViewAnimationOptionTransitionNone
                     animations:^{
                         CGSize dialogSize = [self countDialogSize];
                         CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
                         self.frame = CGRectMake(0, 0, screenWidth, screenHeight);
                         self->dialogView.frame = CGRectMake((screenWidth - dialogSize.width) / 2, (screenHeight - keyboardSize.height - dialogSize.height) / 2, dialogSize.width, dialogSize.height);
                     }
                     completion:nil
     ];
}

and don' forget to pass [UIDevice currentDevice] as object to notification in init:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants