繁体   English   中英

iphone autorotation动画

[英]iphone autorotation animation

是否可以关闭自动旋转的动画? 我想让它旋转,但我只是不想要动画发生(就像一个即时开关)。

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

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

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

只需添加以下代码即可覆盖标准旋转动画:

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

@Nils蒙克不幸的是,这并不正常工作,setStatusBarOrientation预计UIInterfaceOrientationUIDeviceOrientation和铸造是不好的做法。 如果我错了,请纠正我

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM