10

我在这里面临一个奇怪的问题。

出于某种原因,我在视图控制器的方向更改期间禁用了动画,[UIView setAnimationsEnabled:NO];
但是当警报视图存在并且如果我更改方向时,它会给出奇怪的结果。

附加的屏幕截图是当我将方向更改为横向时。

横向模式

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

根据文档

If you disable animations, code inside subsequent animation blocks is still executed but no animations actually occur. Thus, any changes you make inside an animation block are reflected immediately instead of being animated.

所以它不应该影响默认覆盖的调整大小。Is it a restriction in disabling animation !??

我不明白为什么我会这样。任何人都可以帮助解决这个问题。

4

3 回答 3

4

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

当警报视图出现在屏幕上时,您可以选择限制方向,如下所示。

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

BOOL shouldRotate;

YES用in初始化它viewDidload

每当你当时表现出警觉时shouldRotate = NO;

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

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

希望能帮到你。

编辑:因为你想要没有动画和旋转警报视图

这实际上是一个黑客,但有效,

alertUIAlertView在 .h 文件中声明的 ' 对象。

- (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);
    }
}
于 2013-06-04T12:55:16.900 回答
3

解决此错误的另一种可能性是在旋转之前以编程方式关闭警报视图,并在旋转完成后显示一个新视图。

这将自动适用于任何独立于屏幕尺寸的 iOS 设备。

于 2013-06-07T21:01:36.310 回答
0

这似乎是一个错误,iOS6并在iOS7.

没有动画的iOS警报视图

于 2013-10-07T12:25:29.010 回答