shouldAutorotateToInterfaceOrientation:
Returns a Boolean value indicating whether the view controller supports the specified orientation.
(Deprecated in iOS 6.0. Override the supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation methods instead.)
( http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html )
したがって、新しいバージョンで使用できる 2 つの方法は次のとおりです。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/preferredInterfaceOrientationForPresentation
と
- (NSUInteger)supportedInterfaceOrientations
この方法では、次のビットマスクを使用します。
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations
アップデート:
OK、なぜうまくいかないのかわかりません。
あなたがやろうとしていることを再現するデモアプリを作成しました:
(右クリック > 画像の URL をコピーし、新しいブラウザー タブで開いて大きな画像を表示します)

方向フラグが NO の場合、ボタンのテキストに「横向きが拒否されました」と表示され、シミュレーターでデバイスを回転させても、期待どおりにインターフェイスが回転しません。

ただし、ボタンをクリックして横向きを許可した後、シミュレータ デバイスを回転させると、予想どおり、実際にはインターフェイスの向きが変わります。

別のルート ビュー コントローラーに、現在のビュー コントローラーの方向デリゲート メソッドをオーバーライドする他の方向デリゲート メソッドはありませんか?
また、Auto Layout を使用すると干渉するかどうかもわかりませんが、使用しない傾向にあります。XIB ファイル内のビューで、"View" オブジェクトを選択し、インスペクターで" " のチェックを外しましUse Auto Layout
た。上記のサンプル プロジェクトのスクリーンショットは、自動レイアウトを使用していません。
更新 2:
さて、ウィンドウのルートビューコントローラーとしてナビゲーションコントローラーを使用するこのソリューションを見つけました(これを AppDelegate.m に入れます):
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSUInteger orientations =UIInterfaceOrientationMaskAllButUpsideDown;
if(self.window.rootViewController)
{
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}
return orientations;
}
この Stackoverflow の投稿で:
UiNavigationController の iOS 6 AutoRotate
ナビゲーション コントローラーを含む新しいスクリーンショット:

