UIAlertView changes to landscape when App is locked in portrait only in iOS8

时间秒杀一切 提交于 2019-12-19 05:58:21

问题


I have an app and its orientation is locked as portrait mode, but when I have a UIAlertView and turn the iPhone to landscape, the alert changes the orientation and crops the alert's overlay. Only in iOS8.

Anyone had this error?


回答1:


Yes I did get this issue. I have developed my code in iOS7 but had to do compatible with iOS 8 also. So I came across This link. I got my solution as follows:

When you are working with iOS7 UIAlertView works fine but if you are working with iOS8 you have to use UIAlertController. Use this kind of code:

if(SYSTEM_VERSION_LESS_THAN(@"8.0"))
 {
   alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Invalid Coupon."  delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
 }
        else
       {
        UIAlertController *alertController = [UIAlertController    alertControllerWithTitle:@"Warning" message:@"Invalid Coupon." preferredStyle:UIAlertControllerStyleAlert];


        UIAlertAction *okAction = [UIAlertAction
                                   actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                                   style:UIAlertActionStyleDefault
                                   handler:^(UIAlertAction *action)
                                   {

                                   }];

        [alertController addAction:okAction];

        [self presentViewController:alertController animated:YES completion:nil];
    }

Hope this will help you.



来源:https://stackoverflow.com/questions/26258693/uialertview-changes-to-landscape-when-app-is-locked-in-portrait-only-in-ios8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!