そのため、メソッドを呼び出さずにコントローラーが回転するという問題を解決しようとすることをあきらめました。これはshouldAutorotateToInterfaceOrientation:
、数年間、誰もが iOS のバグとして述べてきたためです。
ここで、強制的に回転させる必要がありますUIViewController
。UIDevice
インスタンスメソッドが削除され、コントローラーを強制的に回転させる方法がわからないため、それを行う方法はありますか?
そのため、メソッドを呼び出さずにコントローラーが回転するという問題を解決しようとすることをあきらめました。これはshouldAutorotateToInterfaceOrientation:
、数年間、誰もが iOS のバグとして述べてきたためです。
ここで、強制的に回転させる必要がありますUIViewController
。UIDevice
インスタンスメソッドが削除され、コントローラーを強制的に回転させる方法がわからないため、それを行う方法はありますか?
どのUIDevice
メソッドが削除されたと言っているのかわかりませんが、次の方法でうまくいきました(これはUIDevice
orientation
メソッドを使用しています)。要するに、横向きのみを受け入れるビューがある場合は、次を使用して iOS に向きを強制的に変更させることができます。好奇心旺盛ですが、うまくいきます。元の作者を信用できないことをお詫びしますが、StackOverflow の他の場所でこれに出くわしたことがあります。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)forceLandscape
{
// make sure shouldAutorotateToInterfaceOrientation is configured to accept only landscape
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];
}
}
ポートレートモードを強制するのと同等です(もちろん、shouldAutorotateToInterfaceOrientation
ポートレートのみを受け入れると仮定します):
- (void)forcePortrait
{
// make sure shouldAutorotateToInterfaceOrientation is configured to accept only portrait
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];
}
}