【问题标题】:iOS Animate UIPicker height changeiOS Animate UIPicker 高度变化
【发布时间】:2018-05-23 00:54:47
【问题描述】:

我有带有静态单元格的 UITableView。我已将相等的内容视图高度约束设置为等于 UIPicker 视图高度。我还通过更改 UITableViewCell 内容视图实现了 didSelectRowAt 方法。 https://youtu.be/lJuTLQ1oTaE

魔术发生了,改变 TableViewCell 的高度是动画的。但是 UIPickerView 高度的以下变化同时发生,没有动画。我曾尝试将 UIView.animate 与 layoutIfNeeded() 一起使用,但没有帮助。

如何为 UIPickerView 高度的这种自动变化设置动画?

// TableView functions
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if let cell = tableView.cellForRow(at: indexPath) {
        let reuseIdentifier = cell.reuseIdentifier
        guard reuseIdentifier != nil else {return}

    if reuseIdentifier == "currencyPickerTableViewCell" && self.selectedCellIndexPath == nil {
        self.skipCellsFromGestureRecognition.append(indexPath)
        self.selectedCellIndexPath = indexPath
        print(currencyPicker.constraints)
        tableView.beginUpdates()
        tableView.endUpdates()
    } else if reuseIdentifier == "currencyPickerTableViewCell" && self.selectedCellIndexPath != nil {
        self.selectedCellIndexPath = nil
        self.tableView.beginUpdates()
        self.tableView.endUpdates()
    }
}
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if self.selectedCellIndexPath == indexPath {
        return self.selectedCellHeight
    } else {
        return self.unselectedCellHeight
    }
}

【问题讨论】:

    标签: ios swift uipickerview


    【解决方案1】:

    动画确实发生了,但是由于 UIPicker 的字体保持不变,您看不到它,因此请更改 UIView.animate 内的字体,还要注意您的选择器宽度是静态的,因此,随着字体变大,修剪字符的数量将增加。 . .

    【讨论】:

    • 你可能误解了我的问题。我不改变字体和它的大小。我正在尝试用行扩展 UIPickerView。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 2016-10-04
    • 1970-01-01
    • 2015-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多