在Interface Builder取向处理(Orientation handling in Int

2019-09-17 10:13发布

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

我需要做到以下几点:

  • 不同图像的UIImageView在这两种模式。
  • 表中的每个单元需要具有3/4的图像布局侧由端(3中纵向和4在横向)。

所有这一切都需要在界面生成器做(以最大可能的范围内)。

我迄今为止尝试:

  • IB确实给你定位为视图选项。 但我无法找到每个方向设置不同的图像的方式。
  • 以下的层级,其中我导出从一个单一的基类2级独立的VC(设有2点独立钞)。 唯一的问题是,这是一个通用的构建,所以我必须在这两个iPad和iPhone每个视图做到这一点。

有没有其他更好的方法? 如果不是,是第二选择更好? 这种做法的任何问题?

Answer 1:

你想实现的是将不同的意见基础上的取向在厦门国际银行是什么,简单的答案是,你不能,

但是你可以实现2个Xibs,一个XIB每个方向请参考这个问题作进一步解释的答案,以支持多方位最简单的方法? 当应用程序是在园林如何加载自定义NIB?

这并不为你做?



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


文章来源: Orientation handling in Interface Builder