RootViewController によって制御される複数の UIViewControllers を使用してアプリケーションを構築しています。現在、plist では、アプリケーションのデフォルトは LandscapeRight です。
RootViewController にロードできる次のファイルがあるとします。
- IntroView (横向き右のみ)
- LandscapeView (横向き右のみ)
- PortraitView (縦長のみ)
また、RootViewController の shouldAutorotateToInterfaceOrientation に以下を追加しました。
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([currentClass class] == PortraitView.class) {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
} else {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
}
したがって、PortraitView と viewWillAppear にロードするまで、すべて問題ありません。次を追加します (このスレッドに似ています)。
if (self.interfaceOrientation == UIInterfaceOrientationPortrait) { //UIInterfaceOrientationLandscapeRight) {
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 320, 480);
self.view.center = CGPointMake(240.0f, 160.0f);
}
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
これにより、PortraitView に適切に読み込まれますが、PortraitView 内に 2 つのサブビューがあり、それらを切り替えたいのですが、ビューを回転させたため、UIViewAnimationTransitionFlipFromLeft により、実際には左から右ではなく上から下に反転します。PortraitViewにそれがPortraitであることを伝える方法を私は一生理解できません。
[[UIDevice currentDevice] の向き] を確認すると、ランドスケープであることがわかります。shouldAutorotateToInterfaceOrientation を使用して Portrait only に設定しようとすると、ビューが回転するため、正しくなくなります。
うまくいけば、これは理にかなっています!一日中この問題を見ています。
ありがとう!