【问题标题】:Animate UIView width does not work动画 UIView 宽度不起作用
【发布时间】:2023-04-09 07:09:01
【问题描述】:

尝试像这样为UIView 的宽度设置动画。但它什么也没做。为什么?注释部分更改了视图的alpha,并且有效。

UIView.animate(withDuration: 1, delay: 0, options: [.curveEaseInOut], animations: {

    self.constraintLookupWidth.constant = 300
    self.viewLookup.setNeedsLayout()
    //self.viewLookup.alpha = 0.2

}, completion: {complete in

    self.constraintLookupWidth.constant = 200
    self.viewLookup.setNeedsLayout()
    //self.viewLookup.alpha = 1.0
})

【问题讨论】:

标签: ios animation uiview uiviewanimation


【解决方案1】:

我想您需要将调用与layoutIfNeeded() 集成,这要求自动布局立即强制布局。

【讨论】:

    猜你喜欢
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多