Interface Builder中的方向处理

我需要在我的应用程序中处理方向(肖像 – 风景)。 我的屏幕的基本布局是UIView – > UIImageView – > UITableView(背景= ClearColor)(在Z顺序),使它看起来像表中有一个背景图像。

我需要执行以下操作:

  • 在两种模式下的UIImageView不同的图像。
  • 表中的每个单元需要并排布置3/4个图像(纵向3个,横向4个)。

所有这些都需要在界面生成器中完成(尽可能地)。

我到目前为止所尝试的:

  • IB确实为您提供了“查看方向”的选项。 但是我找不到为每个方向设置不同图像的方法。
  • 遵循一个层次结构,我从一个基类派生出2个独立的VC(带有2个独立的NIB)。 唯一的问题是这是一个通用的构build,所以我必须在iPad和iPhone的每个视图做到这一点。

还有其他更好的方法吗? 如果不是,第二个select更好? 这种方法的任何问题?

你想要实现的是在xib中添加基于方向的不同视图,简单的答案是你不能,

但是你可以实现2个Xib,每个方向一个Xib请参考这个问题的答案进一步的解释最简单的方法来支持多个方向? 如何在应用程序处于横向模式时加载自定义的NIB?

这是否为你做?

请检查下面的代码,它也支持方向

- (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; }