我将尝试使用此代码,但不起作用。
let contentMode: UIView.ContentMode = imageView.contentMode == .scaleAspectFill ?
.scaleAspectFit : .scaleAspectFill
UIView.animate(withDuration: 0.5) {
self.imageView.contentMode = contentMode
}发布于 2022-02-24 18:58:37
你不能这么做。这不是一个可动的属性。现在还不清楚什么样的动画会有意义。
另一种选择是用不同的内容模式替换第二个图像视图,并将其从一个图像视图交叉到另一个图像视图(转换)。
发布于 2022-02-26 17:18:49
你为什么不直接给UIImageView本身动画呢?下面的代码是一个成长动画的例子。
let height = imageView.frame.height
let width = imageView.frame.width
let x = imageView.frame.origin.x
let y = imageView.frame.origin.y
imageView.frame = CGRect(x: x, y: y, width: 0, height: 0)
UIView.animate(withDuration: 0.5) {
self.imageView.frame = CGRect(x: x, y: y, width: width, height: height)
}发布于 2022-08-07 06:12:58
,我是在转换的帮助下完成的
let contentMode: UIView.ContentMode = imageView.contentMode == .scaleAspectFill ? .scaleAspectFit : .scaleAspectFill
UIView.transition(with: imageView, duration: 0.5, options: .transitionCrossDissolve, animations: {
self.imageView.contentMode = contentMode
})https://stackoverflow.com/questions/71256042
复制相似问题