iPadローテーション、方向に基づいてカスタムビューをロードする方法はありますか?
-
30-09-2019 - |
質問
オリエンテーションに基づいてさまざまなビューを表示したいアプリを書いています。たとえば、デバイスがポートレートロードPViewの場合、Landscape Load LViewの場合。以下は、現在試されたコードです。
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
self.view = landscape;
}
}
これにより、IBで2つのビューを作成し、アウトレットを正しいビューに接続しました。私もこれを試しました:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil];
[self.navigationController pushViewController:abo animated:NO];
[abo release];
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil];
[self.navigationController pushViewController:abo animated:NO];
[abo release];
}
}
上記のコードはiPadでは機能しませんでしたが、iPadでは機能しませんでした。何か案は?
解決
次の2(Apple)サンプルプロジェクトが役立つことがわかりました。
http://developer.apple.com/library/ios/#samplecode/alternateviews/introduction/intro.html
http://developer.apple.com/library/ios/#samplecode/whichwayisup/introduction/intro.html
また、デバイスの観点からは、表向きの向きと対決もあることを忘れないでください。これは私を捕まえました。
他のヒント
私は明らかな質問をしなければなりません:
iPadのスクリーンオリエンテーションロックスイッチをオンにしていますか?
あなたがやろうとしていることに応じて、IBでインターフェイスを設定して、回転を自動的に処理することができます。コンポーネントのサイズを変更したり、写真やラベルを動かしたり、そのようなものを移動できます。それはあなたがやりたいことをするかもしれません...
所属していません StackOverflow