gpt4 book ai didi

ios - 使用 2 个组件在 UIPickerView 中水平移动隐藏行

转载 作者:行者123 更新时间:2023-11-28 15:07:55 24 4
gpt4 key购买 nike

我有一个 UIPickerView有 2 个组件:

enter image description here

然而,隐藏的行向中心移动。我认为这与 UIPickerView 放置在“轮子”之间的空间有关。

我在 iOS 相当简短的文档中没有看到任何内容讨论如何防止这种情况发生。

这是我的代码:

func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat
{
return self.currenciesPicker.width / 2
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat
{
return 50.0
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView
{
var cell: CurrencyPickerCell

if view == nil
{
let width = self.pickerView(pickerView, widthForComponent: component)
let height = self.pickerView(pickerView, rowHeightForComponent: component)
cell = CurrencyPickerCell(frame: CGRect(x: 0.0, y: 0.0, width: width, height: height))
}
else
{
cell = view as! CurrencyPickerCell
}

let code = self.codes[row]
cell.nameLabel.text = Currency.names[code]
cell.symbolLabel.text = Currency.symbols[code]

return cell
}

当我让 widthForComponent 返回选取器大小减去 20 的一半时,单元格只显示小 20 点。这会在选取器 View 的左右两端创建空边框。它不会改变这种奇怪的“视差”。

  • 有谁知道造成这种情况的原因以及如何预防这种情况?

  • 我应该如何计算 widthForComponent(选择器宽度的一半是否正确)?

最佳答案

不幸的是,这就是 UIPickerView 控件的设计方式。它应该看起来像您从正上方看的并排坐着的几个轮子。考虑到 Apple 对平面设计风格的所有插入,但没有办法改变它,这有点奇怪。

唯一真正的选择是自己做,完全手动或可能继承 UIPickerView 并自己处理绘图,或者使用第 3 方控件。

关于ios - 使用 2 个组件在 UIPickerView 中水平移动隐藏行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48191009/

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