xCode 4.2にアップグレードしましたが、これは新しいストーリーボード機能です。ただし、縦向きと横向きの両方をサポートする方法を見つけることができませんでした。
もちろん、私はプログラムでそれを行いました。昔のように、ポートレート用とランドスケープ用の2つのビューを使用しました。
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
しかし、私はこれをどうにかして自動的に行う方法を探していました。つまり、今はxCode 4.2ですが、もっと期待していました。皆さんありがとう。
==================================
一時的な解決策:
ここで一時的な解決策を紹介します。私はそれが一時的なものだと言います、なぜなら私はまだAppleの人たちがこれについて本当に賢いことをするのを待っているからです。
「MainStoryboard_iPhone_Landscape」という別の.storyboardファイルを作成し、そこにランドスケープビューコントローラーを実装しました。実際には、通常の(ポートレート).storyboardとまったく同じですが、すべての画面がランドスケープモードになっています。
そこで、横向きのストーリーボードからViewControllerを抽出し、回転が発生したら、self.viewを新しいviewControllerのビューに変更するだけです。
1.向きが変わったときに通知を生成します。
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
2.通知を探します:
[[NSNotificationCenter defaultCenter] addObserverForName:UIDeviceOrientationDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
// We must add a delay here, otherwise we'll swap in the new view
// too quickly and we'll get an animation glitch
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}];
3.updateLandscapeViewを実装します
- (void)updateLandscapeView {
//> isShowingLandscapeView is declared in AppDelegate, so you won't need to declare it in each ViewController
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !appDelegate().isShowingLandscapeView)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_Landscape" bundle:[NSBundle mainBundle]];
MDBLogin *loginVC_landscape = [storyboard instantiateViewControllerWithIdentifier:@"MDBLogin"];
appDelegate().isShowingLandscapeView = YES;
[UIView transitionWithView:loginVC_landscape.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{
//> Setup self.view to be the landscape view
self.view = loginVC_landscape.view;
} completion:NULL];
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) && appDelegate().isShowingLandscapeView)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
MDBLogin *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"MDBLogin"];
appDelegate().isShowingLandscapeView = NO;
[UIView transitionWithView:loginVC.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{
//> Setup self.view to be now the previous portrait view
self.view = loginVC.view;
} completion:NULL];
}}
皆さん、頑張ってください。
PS:Ad Taylorの回答を受け入れます。長い間待って解決策を探した後、彼の回答から着想を得たものを実装することになったからです。テイラーに感謝します。