UIAlertview is showing in portrait mode when screen is in landscape mode

965 views Asked by At

I have an application that is configured to support Portrait mode only. But I have to show one screen (say abcViewController) in my application in landscape mode. When abcViewController screen is pushed ,orientation changes from Portrait mode to Landscape mode. In that abcViewController screen statusBar, all images ,buttons are shown in landscape mode but UIAlertView is displayed in PortraitMode. This means everything on view changes to landscape mode in abcViewController but UIAlertView doesn’t rotate to Landscape mode and remain in Portrait Mode. I would like the UIAlertView to follow the rules of the containing view controller and show same orientation as statusBar.

enter image description here

Note: I m running my app on iOS 8.0 using Xcode 5.0 and I am searching for the solution which supports Xcode 5.0

1

There are 1 answers

1
ajeet sharma On

Actually, I rotated UIView and status bar of this class programmatically for iOS 7 and earlier iOS versions,but I was having this problem of orientation problem in iOS 8, then I read a new change of iOS 8 which is related to orientation which is given below:

I ran the following code in both iOS 7 and iOS 8:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landscape = (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight);
NSLog(@"Currently landscape: %@, width: %.2f, height: %.2f", 
      (landscape ? @"Yes" : @"No"), 
      [[UIScreen mainScreen] bounds].size.width, 
      [[UIScreen mainScreen] bounds].size.height);

The following is the result from iOS 8:

Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 568.00, height: 320.00

Comparing to the result in iOS 7:

Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 320.00, height: 568.00

so, I got to know [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8.

After reading this new change of iOS 8 I created a new class for iOS 8, so you have two solutions for this issue.

Solution 1: You should use UIAlertController instead of UIAlertView.

Solution 2: You can create a new class for iOS 8 for which you are facing this orientation issue.