この問題に関連する多くの質問があることは承知していますが、私の問題を解決する質問は見つかりませんでした。
まず、このコードを menu.h に設定しました。
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES; }
ステータス バーは方向によって変化しますが、ビューは回転またはサイズ変更されません。問題を絞り込むために、方向に基づいて 1 つの .xib 内で 2 つのビューを切り替えることにしました。
- (void)viewDidLoad {
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
-(void) orientationChanged:(NSNotification *)object
{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
iOS シミュレーターでは、ビューは確実に特定のビューに変わります。ただし、横向きのビューは、縦向きで横向きのように表示されます。
IB での私の横向きビュー
向きを変更した後の iOS シミュレーターの横向きビュー
ここで何が間違っていますか?私はそれを理解できません、どんな助けでも大歓迎です。前もって感謝します。** 編集: 以下の新しいコード ** わかりました..私の問題は、ビューが横向きに正しく読み込まれることです。横向きです。そのため、Landscape ビューがロードされ、横向きになります。@Seegaに基づく私の修正されたコードは次のとおりです。
- (void)viewDidLoad {
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
[[TTNavigator navigator] setCustomTarget:self];
[[TTNavigator navigator] setCustomAction:@selector(photoAction)];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIDeviceOrientationLandscapeLeft || toInterfaceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
-(void) orientationChanged:(NSNotification *)object
{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}