当App仅在iOS8中以纵向锁定时,UIAlertView会更改为横向

Sal*_*lmo 8 iphone orientation uialertview xcode6 ios8

我有一个应用程序,它的方向被锁定为纵向模式,但当我有一个UIAlertView并将iPhone转为横向时,警报会改变方向并裁剪警报的叠加层.仅限iOS8.

有人有这个错误吗?

iAn*_*rag 14

是的,我确实得到了这个问题.我已经在iOS7中开发了我的代码,但也必须与iOS 8兼容.所以我遇到了这个链接.我的解决方案如下:

当您使用iOS7时,UIAlertView工作正常,但如果您使用的是iOS8,则必须使用UIAlertController.使用这种代码:

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];
    }
Run Code Online (Sandbox Code Playgroud)

希望这会帮助你.