質問

この状況でAutoLayoutが役立つかどうかを編集するために?

UILABELに画面上の固定位置を維持しても、まだ回転させるにはどうすればよいですか? shuldautorotatetointerfaceorientationはyesを返しており、ラベルは正常に回転していますが、どのようにxcodeのstrutsを設定しても、ラベルの位置を変更します。

最初の画像は、4つの個別のuilabelsを使用して、ストーリーボードでレイアウトを作成した方法を示しています。 2番目の画像は、私が望むものではなく、風景がどのように表示されるかを示しています。 3番目の画像は、各数字の回転アニメーションが数字自体を中心とした状態で、ランドスケープをどのように見たいかを示しています。

This is how I've created the layout in storyboard, with four individual UILabels. This is how landscape appears -- not what I want. Here is what I would like landscape to look, with the rotation animation of each number centered on the number itself.

役に立ちましたか?

解決

VRKは彼の答えで正しい軌道に乗っていますが、 shouldAutorotateToInterfaceOrientation: ラベルをレイアウトするための適切な方法ではありません。あなたが受け取るとき shouldAutorotateToInterfaceOrientation:, 、新しいオリエンテーションのためにまだ更新されていません。

あなたはあなたの意見をレイアウトする必要があります willAnimateRotationToInterfaceOrientation:duration:. 。として ドキュメント 州:

この方法が呼ばれるまでに、 interfaceOrientation プロパティはすでに新しいオリエンテーションに設定されており、ビューの境界が変更されています。したがって、この方法でビューに必要な追加のレイアウトを実行できます。

あなたもできます アニメーション この方法での新しいポジションに対するあなたの見解。

他のヒント

ラベル(Transformatin)で回転を実行できます。 uiviewcontrollerのinterface -orientationメソッドでそれを行います。

uilabel.transform = cgaffinetransformmakerotation(m_pi / -4);このような。 4つの方向すべてでこれを実行します。そして、デバイスの向き以外のAppDelegateからStatusBarの向きをとることが1つあります。ビューオリエンテーションと同期し続けるのに役立ちます。

Shouldautorotatointerfaceorientationメソッドで、ラベルのフレーム位置値を手動で設定する必要があります

水平方向に1つ、垂直に2つのuilabelを作成します。オリエンテーションを変更するときに、必要なラベルを非表示にして表示します。これを行うには、viewdidloadを入力する必要があります。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

実装します

- (void) didRotate:(NSNotification *)notification{

       UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

       if (orientation == UIDeviceOrientationLandscapeLeft)
       {

          // show Horizontal Label
       }
       ....
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top