Tabbar-Application (Landscape-Portrait) で 1 つのタブのみのビューを変更しますか?
-
19-09-2019 - |
質問
iPhoneを回転させたときにビューを変更するにはどうすればよいですか(ペン先を変更する)。ただし、これは 1 つのタブでのみ発生するはずです。私はそれを試してみました:
- (void)viewDidLoad {
LandscapeViewController *viewController = [[LandscapeViewController alloc]
initWithNibName:@"LandscapeView" bundle:nil];
self.landscapeViewController = viewController;
[viewController release];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil]; }
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
ただし、すべてのタブにランドスケープビューが表示されます。(このコードが一度ロードされたとき)。何か案が?
解決 3
あなたのコメントのためのタンク! 私は回避策を見つけます:
//Remove Observer if not in Landscape
- (void)viewDidDisappear:(BOOL)animated {
if (isShowingLandscapeView == NO) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
}
//Add Observer if not in Landscape
- (void)viewDidAppear:(BOOL)animated {
if (isShowingLandscapeView == NO) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
}
他のヒント
何が起こっているのかというと、ビューコントローラーが UIDeviceOrientationDidChangeNotification
表示されているかどうかに関係なく、回転が変更されるたびに通知を受け取ります。代わりに、次の組み込みメソッドを使用してみてください。 UIViewController
回転に応答するためのものです。
これは、Appleのドキュメント(ビューコントローラプログラミングガイド)からです。
タブバーコントローラとビューの回転
タブバーコントローラは、肖像画をサポート デフォルトではオリエンテーションとしません 横向きに回転させます ルートビューのすべての場合を除き コントローラは、このようなサポート オリエンテーション。場合は、デバイスの向き 変更は、タブバーコントローラを発生します ビューコントローラのその配列を照会します。 それらのいずれか1つがサポートされていない場合 オリエンテーション、タブバー コントローラは変更されません。その オリエンテーションます。
だから、私はタブバーコントローラは、単一のビューのためだけに回転するように設計されていることを確認していないよ。
所属していません StackOverflow