6

iPhoneシミュレーターとiPhone3GS(iOS 6)の両方で、向きを逆さまに縦向きに設定することができません。ViewControllerは1つだけです。私はそれにこのコードを追加しました:

-(BOOL) shouldAutorotate{
 return YES; 
}

-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
 return UIInterfaceOrientationPortraitUpsideDown;
}

- (NSUInteger)supportedInterfaceOrientations{
 return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
  if (toInterfaceOrientation==UIInterfaceOrientationPortrait || toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
    return YES;
  }
 return NO;
}

これもAppDelegate.mに追加しました。

-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}

plistファイルも確認しましたが、両方の方向がそこにあります。私のストーリーボードでは、シミュレートされたメトリックで方向が推定に設定されています。YESを返す以外は、applicationDidFinishLaunchingWithOptionsでは何もしません。このViewController内にUIImageViewを追加しました。このオリエンテーションを機能させることは可能ですか?

4

3 に答える 3

11

supportedInterfaceOrientationsを返しますNSUInteger。ビューコントローラがサポートするすべてのインターフェイス方向、インターフェイス方向値のマスクを返します。

UIInterfaceOrientationMask次のように、列挙型で定義された値を返す必要があります。

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
于 2012-12-27T16:38:10.330 に答える
1

私はうまくいった答えがあることを知っていますが、それでも同じ問題で立ち往生している他の人のために:

Xcodeに関連する同様の問題がありました。すべてのケースに戻っYESたにもかかわらず、縦向きの回転がサポートされていませんでした。- (BOOL) shouldAutorotateToInterfaceOrientation:ターゲットのプロジェクトエディタの概要ウィンドウで、有効になっている「サポートされているインターフェイスの向き」であることが判明しました。

ここに画像の説明を入力してください

上記の「iPhone/iPadDepoloyment Info」の選択はそれを行っていませんでした。私がiPhonesimのみを使用していたにもかかわらず、シミュレーターが何をするかを制御しているように見えるのは「iPadDeploymentInfo」セクションでした。そのセクションで同じ向きを有効にすると、iPhoneシミュレーションが機能し、シミュレーターを回転させたときに何が起こったかをテストできました。

于 2013-04-17T10:33:25.583 に答える
0

私はこれのために多くの方法を試しました。それはそれが機能する唯一の方法のようですが、特定のView Controllerだけでなく、アプリを通じてグローバルに機能します。

まず、ターゲットの一般設定でデバイスの向きの逆さまを確認する必要があります。

デバイスの向きの逆さまを確認してください

次に、ナビゲーションコントローラー拡張機能で、supportedInterfaceOrientationsメソッドをオーバーライドします

extension UINavigationController {
    override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return .All
    }
}
于 2016-08-02T06:35:19.577 に答える