wimagguc / ios-custom-alertview

Custom UIAlertView. Continue adding images and UIViews to dialogs in iOS7+
Other
1.66k stars 394 forks source link

Orientation changes broken on iOS9 + Launch Screen Storyboard #89

Open gmondada opened 8 years ago

gmondada commented 8 years ago

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 commented 7 years ago

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 commented 6 years ago

Did you got soultion for this i am facing same issue

kemalserkan commented 6 years ago

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

rayalarajee commented 6 years ago

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

andymedvedev commented 5 years ago

@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]];