
Слева — скриншот на VisionOS, а справа — скриншот на iOS. Серый фон означает, что ячейка выбрана.
Как видно на скриншоте, в VisionOS вокруг ячейки есть некоторое пространство по сравнению с состоянием iOS.
Я могу игнорировать расстояние между левой и правой сторонами ячейки, но расстояние между верхней и нижней частью вызвало некоторые проблемы в моем приложении, поэтому мне пришлось удалить это расстояние.
Я просмотрел документацию по UITableView и поискал в Интернете, но не нашел соответствующей информации.
Этот вопрос возник из библиотеки с открытым исходным кодом: JSONPreview. Эту проблему можно воспроизвести, используя пример проекта в каталоге Demo после клонирования проекта.
Ниже приведены некоторые ключевые исходные коды:
< pre class="lang-swift Prettyprint-override">
Код: Выделить всё
open class LineNumberTableView: UITableView {
public override init(frame: CGRect, style: UITableView.Style) {
super.init(frame: frame, style: style)
config()
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
config()
}
}
private extension LineNumberTableView {
func config() {
bounces = false
delaysContentTouches = false
canCancelContentTouches = true
showsVerticalScrollIndicator = false
showsHorizontalScrollIndicator = false
contentInsetAdjustmentBehavior = .never
allowsMultipleSelection = true
estimatedRowHeight = 0
estimatedSectionFooterHeight = 0
estimatedSectionHeaderHeight = 0
#if !os(tvOS)
scrollsToTop = false
separatorStyle = .none
#endif
}
}
//
open lazy var lineNumberTableView = LineNumberTableView(frame: .zero, style: .plain)
// MARK: - UITableViewDelegate
extension JSONPreview: UITableViewDelegate {
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return getLineHeight(at: indexPath.row)
}
}
// MARK: - UITableViewDataSource
extension JSONPreview: UITableViewDataSource {
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lineDataSource.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.backgroundColor = .clear
cell.textLabel?.text = "\(lineDataSource[indexPath.row])"
cell.textLabel?.textAlignment = .right
cell.textLabel?.font = highlightStyle.lineFont
cell.textLabel?.textColor = highlightStyle.color.lineText
return cell
}
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... n-visionos
Мобильная версия