有没有办法在不缩放的情况下更改 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/