iOS Animate UIPicker 高度变化

标签 ios swift uipickerview

我有带有静态单元格的 UITableView。我已设置相等的内容 View 高度约束等于 UIPicker View 高度。我还通过更改 UITableViewCell 内容 View 实现了 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
    }
}

最佳答案

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

关于iOS Animate UIPicker 高度变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47720094/

相关文章:

iphone - IOS:生物体的内存问题和

ios - 切换具有相同数据的两个 View

swift - 在 Mac Catalyst 中使用文档浏览器 View Controller

iphone - 按下 IBAction 后确定 PickerView 值

swift - UIPickerView:未调用 viewForRow

ios - 将 UIWebView 内容保存为 A4 大小的 PDF

ios - 如何在 Swift 4 中向 UIView 添加 subview ?

ios - UIAppearance 边缘插入

ios - UIPanGestureRecognizer 当滑动单元格以获得更多按钮时如果用户滑动不到一半如何使 View 反弹

ios - 为动态创建的 UIPickerView 添加协议(protocol)