在仅portait的文字游戏中,我使用静态单元格来显示IAP存储:
您可以在上面的iPhone 4屏幕截图中看到我的问题-底部的粉红色按钮(观看视频广告并接收150个硬币)不可见。
这是我的Xcode屏幕截图(请单击全屏):
我使用7个静态单元格:
并使用此方法调整单元格的大小:
- (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?
}
我的问题是:对于高度紧凑的设备(自适应布局中的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];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句