2

アプリケーションで向き (縦 - 横) を処理する必要があります。私の画面の基本的なレイアウトは UIView -> UIImageView -> UITableView (Background = ClearColor) (その z オーダー) で、テーブルに背景画像があるように見えます。

次のことを行う必要があります。

  • 両方のモードで UIImageView の異なる画像。
  • 表の各セルには、3/4 の画像を横に並べて配置する必要があります (縦に 3 つ、横に 4 つ)。

これらはすべて、インターフェイス ビルダーで (可能な限り) 実行する必要があります。

私がこれまでに試したこと:

  • IB では、表示方向のオプションを提供しています。しかし、向きごとに異なる画像を設定する方法が見つかりませんでした。
  • 1 つの基本クラスから 2 つの別個の VC (2 つの別個の NIB を持つ) を派生させる階層に従います。唯一の問題は、これがユニバーサル ビルドであることです。そのため、iPad と iPhone の両方でビューごとにこれを行う必要があります。

他に良い方法はありますか?そうでない場合、2番目のオプションの方が優れていますか? そのアプローチに問題はありますか?

4

2 に答える 2

0

オリエンテーションもサポートしている以下のコードをチェックしてください

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CountryCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    //    NSString *continent = [[self.countries allKeys] objectAtIndex:indexPath.row];
    NSString *continent1 = [self tableView:tableView titleForHeaderInSection:indexPath.section];
    NSLog(@"Contine............%@", continent1);
    int k = [[self.countries valueForKey:continent1] count];
    UIScrollView *previewScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 250)];
    previewScrollView.backgroundColor = [UIColor clearColor];
    previewScrollView.pagingEnabled = TRUE;
    previewScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [previewScrollView setContentSize:CGSizeMake(250*k, 60.0)];
    previewScrollView.showsHorizontalScrollIndicator = YES;
    NSLog(@"cell.contentView.frame.size.widt  %f",cell.contentView.frame.size.width);
    NSLog(@"K %@   %d",continent1,  k);
    for(int i=0 ; i<k; i++ ){

        imageView.image = [UIImage imageNamed:[[self.countries valueForKey:continent1] objectAtIndex:i]];
        imageView.contentMode = UIViewContentModeCenter;
        [previewScrollView addSubview:imageView];

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(250.0*i, 10, 200, 250);
        NSLog(@"%@", [NSString stringWithFormat:@"%d%d",indexPath.section,i]);
        btn.tag = [[NSString stringWithFormat:@"%d%d",indexPath.section,i] intValue];
        [btn addTarget:self action:@selector(btnTapped:) forControlEvents:UIControlEventTouchDown];
        [previewScrollView addSubview:btn];
    }

    [[cell contentView] insertSubview:previewScrollView atIndex:0];
    // [cell addSubview:previewScrollView];

}
return cell;
}
于 2012-05-22T07:09:42.430 に答える
0

あなたが達成しようとしているのは、xibの向きに基づいてさまざまなビューを追加することです.短い答えは、あなたができないということです.

ただし、方向ごとに 1 つの xib の 2 つの Xib を実装できます 詳細な説明については、この質問の回答を参照してください 複数の方向をサポートする最も簡単な方法は? アプリケーションがランドスケープの場合、カスタム NIB をロードするにはどうすればよいですか?

これはあなたのためにそれをしますか?

于 2012-05-22T06:34:57.257 に答える