使用动画

时间:2018-06-07 15:24:51

标签: 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
})

1 个答案:

答案 0 :(得分:0)

这似乎太明显了,所以它可能不是你想要的,只需在动画块中设置视图的更新帧。

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

不需要转换。