In my app, I have only one UIViewController
in landscape mode and it works fine if I navigate within the app. But when I present UIAlertController
(for showing alert view) from that landscape viewcontroller and change device orientation, it changes that landscape viewcontroller’s orientation. I tried different solutions like :
UIAlertView crashs in iOS 8.3
iOS 8.3 supported orientations crashs
but none of these work for me. How can I lock UIAlertController
’s orientation?
Note: My app supports iOS9
.
Here is other solution that just lock orientation in the UIAlertController in this way you avoid from losing the ability rotate your screen in the viewController.
PXCustomUIAlertController.h
#import <UIKit/UIKit.h>
@interface PXCustomUIAlertController : UIAlertController
@end
PXCustomUIAlertController.m
#import "PXCustomUIAlertController.h"
@interface PXCustomUIAlertController ()
@end
@implementation PXCustomUIAlertController
- (instancetype)init
{
self = [super init];
return self;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
@end
Then you can important the class and use like this:
PXCustomUIAlertController *alertController = [PXCustomUIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With