オリエンテーションが変更されたときにiPhone回転アニメーションを変更または無効にする
-
02-10-2019 - |
質問
画面の向きが風景からポートレート、またはその逆に変わるときに回転アニメーションを変更または無効にするにはどうすればよいですか?
解決
ビューコントローラーが回転したくない場合は、shoultotatetointerface viewコントローラーメソッドをオーバーライドして、サポートしたくない方向にfalseを返すようにしてください...こちらが参照です.
あなたが他の方法で回転を処理したい場合、あなたは上記の方法でfalseを返すことができ、そうするようにuideviceorientationdidchangenotificationに登録することができます
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(handleOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
今、あなたが通知を取得するとき、あなたはそれであなたが望むことを何でもすることができます...
他のヒント
はい、すべてをバラバラにすることなく、アニメーションを無効にすることができます。
次のコードでは、他のアニメーションやオリエンテーションコードをいじりすることなく、「ブラックボックス」回転アニメーションを無効にします。
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[UIView setAnimationsEnabled:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[UIView setAnimationsEnabled:NO];
/* Your original orientation booleans*/
}
uiviewcontrollerに配置すると、すべてが順調であるはずです。 iOSの望ましくないアニメーションにも同じ方法を適用できます。
あなたのプロジェクトで幸運を祈ります。
上記の@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];
}
所属していません StackOverflow