iOS - iOS 8 中的 UIAlertView/UIAlertController 方向问题

标签 ios xcode orientation uialertview

我在 iOS 8 或更高版本中遇到了一些方向问题。如果应用程序在后台并处于其他方向,同时我的应用程序的某些进程已完成,它会向用户提供 UIAlertView 然后我的 UIAlertView 方向在它处于前景。

我正在使用以下代码来锁定 alertView 方向。

-(void)didPresentAlertView:(UIAlertView *)alertView{
    // UIAlertView in landscape mode
    [UIView beginAnimations:@"" context:nil];
    [UIView setAnimationDuration:0.1];
    alertView.transform = CGAffineTransformRotate(alertView.transform, M_PI_2);
    [UIView commitAnimations];
    NSLog(@"didPresentCalled");
}

请给我一些建议。提前致谢。

最佳答案

UIAlertView 在 iOS 8 中已弃用,因此您需要改用 UIAlertController

NSString *title = @"Title";
NSString *message = @"Message";
NSString *buttonTitle = @"Dismiss";
if (NSClassFromString(@"UIAlertController") != Nil) // Yes, Nil
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:buttonTitle
                                              style:UIAlertActionStyleCancel
                                            handler:^(UIAlertAction *action) {
                                                [self dismissViewControllerAnimated:YES completion:nil];
                                            }]];
    [self presentViewController:alert animated:YES completion:nil];
}
else
{
    [[[UIAlertView alloc] initWithTitle:title
                                message:message
                               delegate:self
                      cancelButtonTitle:buttonTitle
                      otherButtonTitles:nil] show];
}

关于iOS - iOS 8 中的 UIAlertView/UIAlertController 方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27102910/

相关文章:

ios - RestKit ios 相同类型的嵌套对象

ios - UITableViewCell 删除滑动动画丑陋

swift - 使导航栏透明后如何将其更改回半透明

c++ - 无法在仪器中分析 XCTest

java - 在 Android 手机上检查方向

iphone - 在整个应用程序中运行互联网连接检查

objective-c - 将 UIAlertView 委托(delegate)给另一个类/文件?不工作?

ios - 从不同角度观察时,是什么导致部分 SceneKit 几何体进出 "pop"?

android - 如何更改 RecyclerView 的方向?

algorithm - 证明无向图由该算法转化为有向图的最大出度的上界O(log n)