ios - 使用动画更改 UIView 大小而不缩放

标签 ios swift uiview

有没有办法在不缩放的情况下更改 UIView 的大小(宽度和高度)? 例如:

如果我有我的customview并且我想通过动画调整大小:

customview.frame.width = 100
customview.frame.height = 50

致:

customview.frame.width = 100
customview.frame.height = 200

我可以使用 UIView.animate(withDuration: 0.7,animations: {) 来实现吗?

现在我只找到带有比例的示例,如下所示:

let originalTransform = self.main.transform
let scaledTransform = originalTransform.scaledBy(x: 0.2, y: 0.2)
let scaledAndTranslatedTransform = scaledTransform.translatedBy(x: 0.0, y: -250.0)
UIView.animate(withDuration: 0.7, animations: {
    self.main.transform = scaledAndTranslatedTransform
})

最佳答案

这看起来太明显了,所以它可能不是你想要的,但只需在动画 block 中设置 View 的更新帧即可。

UIView.animate(withDuration: 0.7, animations: {
    self.main.frame = someNewRect
})

无需转换。

关于ios - 使用动画更改 UIView 大小而不缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50744983/

相关文章:

ios - 如何在滚动时保持 UICollectionView Cells 的背景颜色不变?

ios - 如果是编辑风格,请重新设计 Tableview Cell

ios - 如何使用 swift3 弯曲 UIView 的顶部?

ios - 添加 Storyboard View 作为以编程方式创建的 View 的 subview

ios - 在 NSDictionary/NSMutableDictionary 中添加数组作为键和值

ios - 从 NSdictionary 准备 NSArray 以在下一个 VC 中显示

ios - UITableView 在文本字段开始编辑时自动滚动

swift - 为什么没有为可选数组定义 Equatable

Swift 核心数据查询生成 Sqlite 错误代码 769(sqlite3_snapshot_open 失败)

ios - 如何在社交媒体帖子中显示 UIView