3

インターフェース全体を1つのストーリーボードにまとめました。ほとんどのViewControllerが縦向きのみをサポートし、カップルのみがすべての向きをサポートするようにするにはどうすればよいですか。りんごの新しい自動回転システムがわかりません。また、これをiOS 5と逆互換にするにはどうすればよいですか?

4

6 に答える 6

10

Navigation Controller サブクラスで、決定をスタック内の最上位のビュー コントローラーに転送します。

-(NSUInteger) supportedInterfaceOrientations {
   return [self.topViewController supportedInterfaceOrientations];
}

このための別のストーリーボード ファイルを作成することは、最悪の方法です。アプリの更新と同期させるためのメンテナンスの悪夢になります。

于 2012-09-26T12:56:21.943 に答える
1

WWDC'2012 のビデオ、特に「要点」セクションでローテーションについて説明しているビデオをご覧ください。

「T Evolution of View Controllers in iOS」と呼ばれるものは、回転に関する主題 (およびさまざまな iOS バージョンと互換性を持たせる方法) を、説明とコード サンプルを使用して詳細に説明しており、Apple よりもうまく説明できませんでした。 )

于 2012-09-22T18:55:31.633 に答える
0

さて、私はこれを回避する方法をちょっとハックしました。ここに私のサブクラス化された NavController.h があります

#import "RootVC.h"

@implementation RootVC

-(BOOL)shouldAutorotate {
    def = [NSUserDefaults standardUserDefaults];
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
    if ([def integerForKey:@"Should Rotate"] == 1) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationMaskPortrait;
}
@end

各ビューコントローラーのデフォルトで @"Should Rotate" に整数を設定するだけです

- (void)viewWillAppear:(BOOL)animated

魔法のように機能します!

于 2012-09-23T23:52:23.780 に答える
0

これが私のサブクラス化された RootNavController.h です

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger) supportedInterfaceOrientations
{
    if (self.topViewController.view.superview)
    {
        return [self.topViewController supportedInterfaceOrientations];
    }

    return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}
于 2012-12-22T09:23:15.887 に答える
0

これは、iOS 5 デバイスと iOS 6 デバイス (および iPhone 5) の両方をサポートするために私が使用したハックです。プレフィックス ファイルに、次の #define を追加します。

#ifdef __IPHONE_6_0 // Only do the rotation fix if we are building with iOS 6 API
@protocol DeprecatedRotationSupported
@optional
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation;
- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end

#define shouldAutorotateToInterface_fixed shouldAutorotate \
{ \
    UIViewController <DeprecatedRotationSupported> *selfTyped = (UIViewController <DeprecatedRotationSupported> *) self; \
\
    if(![self respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) \
        return NO; \
    int optionCount = 0; \
    for(UIInterfaceOrientation orientation = UIInterfaceOrientationPortrait; orientation <= UIDeviceOrientationLandscapeLeft; orientation++) \
    { \
        if(![selfTyped shouldAutorotateToInterfaceOrientation:orientation]) continue; \
        if(optionCount==1) return YES; \
        optionCount++; \
    } \
    return NO; \
} \
\
- (NSUInteger)supportedInterfaceOrientations \
{ \
    UIViewController <DeprecatedRotationSupported> *selfTyped = (UIViewController <DeprecatedRotationSupported> *) self; \
\
    if(![self respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) return UIInterfaceOrientationMaskPortrait; \
    \
    NSUInteger supported = 0; \
    \
    if([selfTyped shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait]) supported |= UIInterfaceOrientationMaskPortrait; \
    if([selfTyped shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft]) supported |= UIInterfaceOrientationMaskLandscapeLeft; \
    if([selfTyped shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight]) supported |= UIInterfaceOrientationMaskLandscapeRight; \
    if([selfTyped shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown]) supported |= UIInterfaceOrientationMaskPortraitUpsideDown; \
    return supported;  \
} \
\
- (BOOL)shouldAutorotateToInterfaceOrientation
#else // We are building with the older API, leave shouldAutorotateToInterfaceOrientation alone.
#define shouldAutorotateToInterface_fixed shouldAutorotateToInterfaceOrientation
#endif // __IPHONE_6_0

次に、 shouldAutorotateToInterfaceOrientation: を使用する場所では、代わりに shouldAutorotateToInterface_fixed: を使用します。

于 2012-11-14T01:07:43.207 に答える
0

ネイティブの rootViewController を使用している場合は、iOS5 を適切にサポートするように拡張する必要があります。これは、上記の WWDC ビデオで述べられています。

基本的に、UINavigationViewController を使用している場合は、それを拡張してその- (NSUInteger)supportedInterfaceOrientationsメソッドをオーバーライドします。そこで、あなたの子供たちを調べて (あなたが持っているインターフェイスの向きについて古いメソッドを照会することができます)、何をサポートすべきかを判断し、正しい値を返します。

下位互換性を保つためにこれを行う必要がある理由は 2 つあります。親は、その子がどの方向にある必要があるかを決定する必要があります。これらの変更はすべて、新しい AutoLayout のものと一致しています。

ナビゲーション コントローラーを拡張したら、ストーリーボードに移動します -> ルート コントローラー (この場合はナビゲーション コントローラー) を選択します -> クラスを新しく作成したクラスに設定します。

HTH

于 2012-09-24T01:15:53.350 に答える