ios - 当存在 UIAlertView 时,没有动画的方向会产生奇怪的结果

标签 ios uialertview uiinterfaceorientation uiviewanimation

我在这里遇到了一个奇怪的问题。

出于某种原因,我在我的 View Controller 中使用 [UIView setAnimationsEnabled:NO];
在方向更改期间禁用动画 但是,当存在警报 View 时,如果我更改方向,则会产生奇怪的结果。

所附的屏幕截图是我将方向更改为横向时的情况。

landscape mode

请注意:我使用的是标准 UIAlertView,它是默认覆盖,当出现警报 View 时显示,此处不涉及自定义。

根据 documentation

如果禁用动画,后续动画 block 中的代码仍会执行,但实际上不会出现动画。因此,您在动画 block 内所做的任何更改都会立即反射(reflect)出来,而不是动画化。

所以它不应该影响默认叠加层的大小调整。 是禁用动画的限制吗!??

我不明白为什么我会变成这样。 谁能帮忙解决这个问题。

最佳答案

当您设置 [UIView setAnimationsEnabled:NO]; 时,UIAlertView 不会调整其覆盖 View 的大小(我认为这是一个错误)。

您可以选择在屏幕上显示警报 View 时限制方向,如下所示。

在 .h 文件中创建一个 BOOL 变量。

BOOL shouldRotate;

viewDidload 中用 YES 初始化它。

每当你在那个时候显示警报时,让 shouldRotate = NO;

并按如下方式实现 UIAlertView 委托(delegate):

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    shouldRotate = YES;
}

希望能帮到你。

编辑:因为你想要没有动画和带有警报 View 的旋转

这实际上是一个 hack 但有效,

alert 是在 .h 文件中声明的 UIAlertView 对象。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    if (UIInterfaceOrientationPortrait == UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) {
        UIImageView *imgView = (UIImageView *)[alert.superview.subviews objectAtIndex:0];
        imgView.frame = CGRectMake(0.0, 0.0, 480.0, 320.0);
    }
    else{
        UIImageView *imgView = (UIImageView *)[alert.superview.subviews objectAtIndex:0];
        imgView.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
    }
}

关于ios - 当存在 UIAlertView 时,没有动画的方向会产生奇怪的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16806816/

相关文章:

ios - 检查用户位置是否靠近某些点

NavigationViewController 中的 iOS AutoLayout 模糊布局

ios - 如何使用 SpriteKit 保存高分?

iphone - 如何将 png 添加到 iPhone 的 UIAlert 按钮

iphone - 在 "centre"模式下,如何在 UIImageView 中缩放图像? (换帧不起作用)

iphone - 如何访问我在相机应用程序中保存的照片的相册?

ios - UIAlertView 按钮将您带到选项卡栏 Controller 中的另一个 View

ios - 我找不到在 UIAlertView 中按下的按钮

ios - Segue 导致 UITabBarController 在 Swift 中向上移动状态栏?

iphone - beginGeneratingDeviceOrientationNotifications 特质?