2

これは可能ですか?どうすればこれを達成できますか?

4

2 に答える 2

2

AppleDocsによると不可能です。

可能な単語には、アスタリスクが必要な場合があります。確かに、Appleはあなたがこれを行うことを想定していなかった(または望んでいなかった)ようです。ただし、要件によっては、回避策がある場合があります。

免責事項:これは一種のハックです。私はこれが優れたUIであるとは主張しておらず、Eliに何が可能かを示しようとしているだけです。

タブ付きアプリケーションを構築するためのXcodeテンプレートから始めて、例を構築しました。2つのViewControllerがあります:FirstViewControllerSecondViewControllerFirstViewController横向きのみのビューにすることにしました。Interface Builder(Xcode UIデザインモード)で、FirstViewControllerのビューの向きを横向きに設定し、サイズを幅480、高さ251にしました(ここではiPhone / iPodを想定しています)。

解決

さて、必要と思われるのは、すべてのタブバーのビューコントローラーが縦向きと横向きへの自動回転をサポートしていると主張することです。例えば:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

したがって、両方のビューコントローラに同じコードがあります。ただし、私が行っているのは、この1つの横向きのみのView Controllerに対して、インフラストラクチャが行うことFirstViewControllerをオーバーライドwillAnimateToInterfaceOrientation:duration:して本質的に元に戻すことです。UIViewController

FirstViewController.m:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration];

    CGAffineTransform viewRotation;
    CGRect frame;

    if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        viewRotation = CGAffineTransformIdentity;
        // TODO: change to dynamically account for status bar and tab bar height
        frame = CGRectMake(0, 0, 480, 320 - 20 - 49);        
    } else {
        viewRotation = CGAffineTransformMakeRotation(M_PI_2);
        // TODO: change to dynamically account for status bar and tab bar height
        frame = CGRectMake(0, 0, 320, 480 - 20 - 49);        
    }

    // undo the rotation that UIViewController wants to do, for this view heirarchy
    [UIView beginAnimations:@"unrotation" context: NULL];
    [UIView setAnimationDuration: duration];

    self.view.transform = viewRotation;
    self.view.frame = frame;

    [UIView commitAnimations];
}

これで得られるのは、タブバーが常にデバイスとともに回転することです。これはおそらく、自動回転を実行するためにデュアルオリエンテーションビュー(たとえばSecondViewController)を取得するための要件です。ただし、現在の実際のビューコンテンツはFirstViewController回転しません。ユーザーがデバイスをどのように回転させても、横向きのままです。だから、多分それはあなたにとって部分的に十分ですか?

また注意してください:

1)アプリのinfo plistファイルを変更して、初期の向きを横向きに設定しました(私FirstViewControllerは横向きだったため):

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>        
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeRight</string>

2) FirstViewController.xibで、メイン/親UIViewをサブビューの自動サイズ変更しないように設定しました。ビュー階層によっては、他の子ビューでもこのプロパティを変更したい場合があります。その設定を試すことができます。

これで、ステータスバーとタブバーが回転するため、横向きのビューで使用できるサイズが少し変わります。そのため、レイアウトを少し調整する必要があるかもしれません。ただし、基本的には、ユーザーがデバイスをどのように持っていても、横向きのコンテンツを表示するための広い視野が得られます。

結果

実行中のアプリのYoutubeデモを見る

于 2012-06-05T01:24:29.457 に答える
2

AppleDocsによると不可能です。すべてのUIViewControllerは、回転可能にするために同じ方向をサポートする必要があります。

このドキュメントを参照してください(「タブバーコントローラと回転」というタイトルのセクションまでスクロールダウンします:http: //developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html#// apple_ref / doc / uid / TP40011313-CH3-SW1

于 2012-06-04T23:29:04.070 に答える