1

だから私はナビゲーションコントローラーを備えたアプリケーションを持っています、最後の1つのビューコントローラーは任意の方向に回転させることができます。そして、他の人は肖像画だけでなければなりません。そのため、横向きの最後のviewControllerを回転させてから、ナビゲーションコントローラーの戻るボタンを押すと問題が発生します。前のものに移動すると、レイアウトが壊れていることがわかります。私は唯一の方法は次のようなものを使用することだと思いました:

[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait] 

(私はそれがハックであることを知っています、そしてそのようなことを避けることが好ましいでしょう)しかし、私がそれを試したところはどこでも-それは私に異なるレイアウトの問題を引き起こしました。次のような通常の方法:

- (NSUInteger)supportedInterfaceOrientations
- (BOOL)shouldAutorotate

この状況では、ハンドルの向きなどは役に立ちません。前もって感謝します。

4

1 に答える 1

0

縦向きにする必要があるviewControllerの親について、この問題を解決しました。

-(NSUInteger)supportedInterfaceOrientations{
 return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
 return UIInterfaceOrientationPortrait;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}

回転viewControllerの場合:

-(NSUInteger)supportedInterfaceOrientations{
 return UIInterfaceOrientationMaskAll;
}

ナビゲーション コントローラーの場合:

- (BOOL)shouldAutorotate {

BOOL result = self.topViewController.shouldAutorotate;

 return result;
}

- (NSUInteger)supportedInterfaceOrientations {

NSUInteger result = self.topViewController.supportedInterfaceOrientations;

return result;
}

そして、これを AppDelegate に追加しました:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
if ([navigationController.topViewController isKindOfClass:[RotationViewController  class]])
    return UIInterfaceOrientationMaskAll;
else
    return UIInterfaceOrientationMaskPortrait;
}
于 2013-03-16T10:43:48.780 に答える