(他の標準の Cocoa Touch コントロールに加えて) 6 つのボタンとラベルを内部に持つサブビューがあります。
この厄介なコードを使用して、回転イベントでこれらのボタンとラベルを回転およびサイズ変更しています。
- (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation {
if (UIInterfaceOrientationIsPortrait(orientation)) {
button1.frame = CGRectMake(20, 59, 130, 80);
button2.frame = CGRectMake(170, 59, 130, 80);
button3.frame = CGRectMake(20, 176, 130, 80);
button4.frame = CGRectMake(170, 176, 130, 80);
button5.frame = CGRectMake(20, 293, 130, 80);
button6.frame = CGRectMake(170, 293, 130, 80);
label1.frame = CGRectMake(20, 147, 130, 21);
label2.frame = CGRectMake(170, 147, 130, 21);
label3.frame = CGRectMake(20, 264, 130, 21);
label4.frame = CGRectMake(170, 264, 130, 21);
label5.frame = CGRectMake(20, 381, 130, 21);
label6.frame = CGRectMake(170, 381, 130, 21);
} else {
button1.frame = CGRectMake(20, 59, 130, 60);
button2.frame = CGRectMake(20, 155, 130, 60);
button3.frame = CGRectMake(177, 59, 130, 60);
button4.frame = CGRectMake(177, 155, 130, 60);
button5.frame = CGRectMake(328, 59, 130, 60);
button6.frame = CGRectMake(328, 155, 130, 60);
label1.frame = CGRectMake(20, 127, 130, 21);
label2.frame = CGRectMake(20, 223, 130, 21);
label3.frame = CGRectMake(177, 127, 130, 21);
label4.frame = CGRectMake(177, 223, 130, 21);
label5.frame = CGRectMake(328, 127, 130, 21);
label6.frame = CGRectMake(328, 223, 130, 21);
}
}
これは少し面倒ですが、問題なく動作し、ビュー内の要素の位置を正確に制御できます。
ちなみに、「CPUパワー」とメモリ消費に関しては、2つの異なるビューを持ち、ローテーションでそれらを反転させる方が効率的かどうか疑問に思っています(2つではなく1つのビューを使用する方がメモリに適していると思いますが、間違っている可能性があります.私はiOSプログラミングにかなり慣れていません)。
ご提案ありがとうございます。