iOS Animate UIPicker高度变化

时间:2017-12-08 18:18:45

标签: ios swift uipickerview

我有静态单元格的UITableView。我已将等内容视图高度约束设置为等于UIPicker视图高度。我还使用更改UITableViewCell内容视图实现了didSelectRowAt方法。 enter image description here 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
    }
}

1 个答案:

答案 0 :(得分:0)

动画确实发生了,但由于 UIPicker 的字体保持不变,你无法看到它,所以更改 UIView.animate 中的字体,同时请注意你的选择器的宽度是静态的,因此,当字体变大时,修剪字符的数量会增加。 。 。

相关问题