【问题标题】:Orientation handling in Interface BuilderInterface Builder 中的方向处理
【发布时间】:2012-05-28 15:16:25
【问题描述】:
我需要在我的应用程序中处理方向(纵向 - 横向)。我的屏幕的基本布局是 UIView -> UIImageView -> UITableView (Background = ClearColor) (在那个 z 顺序中),所以看起来表格有背景图像。
我需要做以下事情:
- 两种模式下 UIImageView 中的不同图像。
- 表格中的每个单元格都需要并排放置 3/4 张图片(3 张纵向和 4 张横向)。
所有这些都需要在界面构建器中完成(尽可能)。
到目前为止我所尝试的:
- IB 确实为您提供了视图方向选项。但我找不到为每个方向设置不同图像的方法。
- 按照我从一个基类派生 2 个单独的 VC(带有 2 个单独的 NIB)的层次结构。唯一的问题是这是一个通用版本,所以我必须为 iPad 和 iPhone 中的每个视图都这样做。
还有其他更好的方法吗?如果不是,第二个选项更好吗?这种方法有什么问题吗?
【问题讨论】:
标签:
ios
xcode
interface-builder
orientation
【解决方案2】:
请查看以下代码,它也支持方向
- (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;
}