![](/img/trans.png)
[英]iPhone Autorotation - Disable view rotation animation BUT transitions to another screen
[英]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預計UIInterfaceOrientation
不UIDeviceOrientation
和鑄造是不好的做法。 如果我錯了,請糾正我
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.