4

是否可以关闭自动旋转的动画?我希望它旋转,但我只是不希望动画发生(如即时切换)。

4

3 回答 3

7

如果你真的需要,只需setAnimationsEnabled使用UIView

- (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
}

它对我有用。当然,除非您有充分的理由这样做,否则不建议这样做。

于 2011-07-05T22:29:23.630 回答
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];
}
于 2011-06-09T11:41:06.237 回答
0

@Nils Munch 不幸的是,这不能正常工作, setStatusBarOrientation 预计UIInterfaceOrientation不会UIDeviceOrientation,并且铸造是不好的做法。如果我错了,请纠正我

于 2013-04-09T08:46:01.473 回答