gpt4 book ai didi

ios - 以编程方式使用自适应布局调整 hCompact 的静态单元格高度

转载 作者:可可西里 更新时间:2023-11-01 05:52:27 25 4
gpt4 key购买 nike

在一个只有肖像的文字游戏中,我使用静态单元格来显示 IAP 商店:

iPhone screenshot

你可以在上面的 iPhone 4 屏幕截图中看到我的问题 - 底部的粉红色按钮(观看视频广告和接收 150 个金币)不可见。

这是我的 Xcode 截图(请点击 fullscreen ):

Xcode screenshot

我使用 7 个静态单元格:

  • 带有后退按钮、标题、钱袋图标的蓝色顶部单元格
  • 状态文本(在上面的屏幕截图中不可见)
  • 硬币包 1
  • 硬币包 2
  • 金币包 3
  • 硬币包 4
  • 视频广告(底部的粉红色单元格 - 存在在 iPhone 4 和其他紧凑型设备上不可见的问题)

然后用这个方法调整单元格的大小:

- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath row] == 0)
return 70;

if ([indexPath row] == 1)
return 35;

return 90; // XXX how to change this to 70 for hCompact?
}

我的问题是:如何为高度紧凑的设备(Adaptive Layout 中的 hCompact 尺寸类)以编程方式调整单元格高度。

更新:

到目前为止,我自己的丑陋解决方案是:

@interface StoreCoinsViewController ()
{
int _cellHeight;
}

- (int)setCellHeight // called in viewDidLoad
{
int screenHeight = UIScreen.mainScreen.bounds.size.height;
NSLog(@"screenHeight=%d", screenHeight);

if (screenHeight >= 1024) // iPad
return 160;

if (screenHeight >= 736) // iPhone 6 Plus
return 110;

if (screenHeight >= 667) // iPhone 6
return 100;

if (screenHeight >= 568) // iPhone 5
return 90;

return 72; // iPhone 4s (height=480) and earlier
}
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath row] == 0)
return 70;

if ([indexPath row] == 1)
return 35;

return _cellHeight;
}

最佳答案

我会写一个帮助程序来查看当前特征集合的垂直大小类

- (CGFloat)verticalSizeForCurrentTraitCollection {
switch (self.traitCollection.verticalSizeClass) {
case UIUserInterfaceSizeClassCompact:
return 70;
case UIUserInterfaceSizeClassRegular:
return 90;
case UIUserInterfaceSizeClassUnspecified:
return 80;
}
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] == 0)
return 70;

if ([indexPath row] == 1)
return 35;

return [self verticalSizeForCurrentTraitCollection];
}

关于ios - 以编程方式使用自适应布局调整 hCompact 的静态单元格高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29728805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com