これは現在、日付を見ている古い質問のビットかもしれませんが、私はまもなく同じ問題に直面しました。メインビューのサブビューやそのレイヤーを変換するなど、多くの提案があります。これのうちのどれも私にとっては役に立たなかった。
私が見つけた唯一の解決策は、UIコントロールを動的に配置したいから、主にインターフェイスビルダーに配置しないことです。インタフェースビルダーは、ポートレートとランドスケープの両方の方向でダイナミックコントロールの望ましい場所を知るのに役立ちます。つまり、インターフェイスビルダーで2つの別々のテストビューを作成し、1つのポートレートと他のランドスケープを作成し、それぞれのコントロールに対してCGRectMakeで使用するX、Y、WidthおよびHeightデータを右下に配置します。
インターフェイスビルダから必要なすべての測位データを書き留めるとすぐに、既に描画されたコントロールとアウトレット/アクションリンクを取り除きます。彼らは今必要ではありません。
もちろん、UIViewControllerのwillRotateToInterfaceOrientationを実装して、各向きの変更でコントロールのフレームを設定することを忘れないでください。
@interface
//Declare your UI control as a property of class.
@property (strong, nonatomic) UITableView *myTable;
@end
@implementation
// Synthesise it
@synthesize myTable
- (void)viewDidLoad
{
[super viewDidLoad];
// Check to init for current orientation, don't use [UIDevice currentDevice].orientation
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
myTable = [[UITableView alloc] initWithFrame:CGRectMake(20, 20, 228, 312)];
}
else if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
{
myTable = [[UITableView alloc] initWithFrame:CGRectMake(78, 801, 307, 183)];
}
}
myTable.delegate = self;
myTable.dataSource = self;
[self.view addSubview:myTable];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
// Show landscape
myTable.frame = CGRectMake(20, 20, 228, 312);
}
else
{
// Show portrait
myTable.frame = CGRectMake(78, 801, 307, 183);
}
}