gpt4 book ai didi

ios - UILabel下的UIVIew动画

转载 作者:行者123 更新时间:2023-11-28 10:57:52 27 4
gpt4 key购买 nike

我想实现这种简单的动画效果:

enter image description here

所以有这两个标签(Label: 和 29.8,在 ViewController 中作为 @IBOutlet weak var valueLabel: UILabel!)和这两个标签下的 UIView(@IBOutlet weak var pm10View: UIView!)不幸的是,CGAffineTransform 不起作用,因为它调整了这个矩形的大小,因为 anchor 位于中心。我试过将 anchor 设置到左上角,但 UIView 放错了地方:

pm10View.layer.anchorPoint = CGPoint(x: 0, y: 0)

UIView.animate(withDuration: 3) {

self.pm10View.transform = CGAffineTransform(scaleX: 2.2, y: 1.0)
}

那么如何将这个 UIView 保持在与 Main.storyboard 中相同的位置(锚定左上角和左下角)并仅调整 Y 值的大小。虽然 UIView 在 UILabel 下,但它是否需要在 Stack View 或其他东西中才能保持一切就位?

最佳答案

抱歉,您的问题不清楚?你想增加标签的宽度吗?如果是这样,

UIView.animate(withDuration: 1.0) { 
yourLabel.frame.size.width = newWidthValue;
yourLabel.layoutIfNeeded()
}

关于ios - UILabel下的UIVIew动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42140900/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com