iPhone自动旋转动画

4

是否有可能关闭自动旋转的动画效果?我希望它可以旋转,但不希望出现动画效果(就像瞬间切换一样)。


动画是它的美丽之处! - Raj Pawan Gumdal
我已经设置好了背景图片,根据方向和旋转动画,它会更改为图像的水平或垂直版本。但是当图像更改时,旋转动画会导致故障,但我进行了调整,使其看起来还可以。 - Brodie
3个回答

7

如果你真的有需要,可以使用UIViewsetAnimationsEnabled

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [UIView setAnimationsEnabled:NO]; // disable animations temporarily
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [UIView setAnimationsEnabled:YES]; // rotation finished, re-enable them
}

对我来说,这个方法很有效。当然,除非你有非常充分的理由,否则不建议这样做。


4
只需添加以下代码即可覆盖标准的旋转动画:
- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)   name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (void)didRotate:(NSNotification *)notification {
    orientation = [[UIDevice currentDevice] orientation];
    if(orientation == UIDeviceOrientationUnknown || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationFaceUp){
        orientation = UIDeviceOrientationPortrait;
    }
    [[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:NO];
    [self positionScreenElements];
}

1
这个答案非常有效,但是我在聚焦文本框时遇到了一些问题。如果iPad平放在桌子上,那么键盘就会显示出半个屏幕 - 非常奇怪。问题在于设备方向也可能是未知的、正面朝上或者正面朝下,这些都不对应状态栏方向。检查这些状态使得它完美无缺。非常感谢Nils用这个解决方案拯救了我 :) - adam.wulf
什么是“方向”? - Morkrom

0
@Nils Munch 很抱歉,这个不起作用,setStatusBarOrientation期望的是UIInterfaceOrientation而不是UIDeviceOrientation,强制转换是不好的实践。如果我错了,请纠正我。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接