[英]iPhone - UIViewController not rotating when device orientation changes
[英]Change or disable the iPhone rotating animation when orientation changes
當屏幕方向從橫向更改為縱向時,如何更改或禁用旋轉動畫,反之亦然?
是的,可以禁用動畫,而不會破壞一切。
以下代碼將禁用“黑匣子”旋轉動畫,而不會弄亂其他動畫或方向代碼:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[UIView setAnimationsEnabled:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[UIView setAnimationsEnabled:NO];
/* Your original orientation booleans*/
}
把它放在你的UIViewController中,一切都很好。 相同的方法可以應用於iOS中的任何不需要的動畫。
祝你的項目好運。
如果您不希望視圖控制器旋轉,只需覆蓋shouldAutoRotateToInterface視圖控制器方法,以便為您不想支持的任何方向返回false ... 這是一個參考 。
在你只是想以其他方式處理旋轉的情況下,你可以在上面的方法中返回false並注冊UIDeviceOrientationDidChangeNotification,就像這樣
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(handleOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
現在,當你收到通知時,你可以隨心所欲地做任何事......
@Nils Munch上面的答案是找到<iOS7。 對於iOS 7或更高版本,您可以使用:
- (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[UIView setAnimationsEnabled:NO];
[coordinator notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[UIView setAnimationsEnabled:YES];
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.