-1

これは重複した質問ではありません。最終的な実用的なソリューションはまだ提供されていません。私が回答を受け入れるか、これに対する独自の解決策を見つけて提供するまで、この質問を閉じないでください。ありがとう!

================================================== ================ Xcode 4.5.1 を使用して、5 つのタブを含むタブバー アプリを作成しました。各タブには UINavigationController が含まれています。そのため、アプリ全体を縦向きモードで表示する必要がありますが、唯一の ViewController (全画面表示で開き、横向きモードで表示するための「モーダル」VC) を除きます。

これは iOS5 で完全に機能しました。特定の ViewController で次のコードを使用しただけです。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

しかし、アプリがクラッシュし、次のエラーが発生します。

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',    
reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

助言がありますか?

4

4 に答える 4

5

使用した xcode のバージョンを確認してください。

XCODE 4.5 を使用しました:shouldAutorotateToInterfaceOrientationデリゲートの減価償却。

プロジェクトで次の行を使用します。

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
    }

-(BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
于 2012-11-01T04:08:47.870 に答える
1

iOS6 のクラッシュを回避するには、これを使用する必要があります。

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown; //Getting error here? then update ur xcode to 4.5+
}
#endif
于 2012-11-01T04:40:13.327 に答える
0

コードは問題ないようです。そのメソッドだけでクラッシュするべきではありませんでした。コードの別の部分に問題がある可能性があります。しかし、ここで私はあなたに伝えたいと思います。上記のshouldAutorotateToInterfaceOrientation方法の向きの方法は、iOS 6 で非推奨になりました。向きの問題を修正する方法について詳しく知りたい場合は、 これをご覧ください。

于 2012-11-01T06:10:27.483 に答える
0

一つ覚えておいてください。iOS 6 では

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

廃止されました。

iOS 6 では使用できません。UINavigationController の viewController で異なるインターフェイスの向きをサポートするには、UINavigationController をサブクラス化するか、そのカテゴリを作成する必要があります。

于 2012-11-01T04:13:16.520 に答える