デバイスの回転時に適切に配置する必要があるcontentView
3つの UI 要素があります。UITableViewCell
現在、これらの UI 要素のフレームを次のように適用しています。
segmentedControl1.frame = CGRectMake(165, 15, 130, 40);
segmentedControl2.frame = CGRectMake(435, 15, 130, 40);
segmentedControl3.frame = CGRectMake(710, 15, 130, 40);
これらの要素の autoresizingMask プロパティを使用して、デバイスが横向きから縦向き (デフォルトは縦向き、iPad のみ) に回転したときに、これらの要素のサイズを変更して互いに重ならないようにする方法を知りたいです。向きごとにカスタムのフレーム位置を設定したくありません。
私はこのようなことを試しました:
segmentedControl1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
segmentedControl2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
segmentedControl3.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
しかし、これはうまくいかないようです。要素はすべて重なり合っており、不幸にもレイアウトされています。
助言がありますか?
更新 1
テーブル ビュー セルは現在、ランドスケープ モードでどのように表示されるかを次に示します。
--------------------------------------------------------------------------
| ============ ============ ============ |
| | A | B | | A | B | | A | B | |
| ============ ============ ============ |
--------------------------------------------------------------------------
そして、デバイスが縦向きモードに回転したときに私が望むものは次のとおりです。
-------------------------------------------------------
| ============ ============ ============ |
| | A | B | | A | B | | A | B | |
| ============ ============ ============ |
-------------------------------------------------------
UPDATE 2 @Wolfert からの提案を組み込んだ cellForRowAtIndexPath の私のコードは次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// Configure the cell...
segmentedControl1.frame = CGRectMake(165, 15, 180, 40);
segmentedControl1.tag = indexPath.row;
segmentedControl1.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[cell.contentView addSubview:segmentedControl1];
segmentedControl2.frame = CGRectMake(435, 15, 180, 40);
segmentedControl2.tag = indexPath.row;
segmentedControl2.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[cell.contentView addSubview:segmentedControl2];
segmentedControl3.frame = CGRectMake(710, 15, 180, 40);
segmentedControl3.tag = indexPath.row;
segmentedControl3.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[cell.contentView addSubview:segmentedControl3];
return cell;
}