ios - UILabel下的UIVIew动画

标签 ios swift uiview uiviewanimation

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

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/

相关文章:

ios - 如何从 NSArray 访问属性?

ios - 带阴影的 UIView - 应用 renderInContext 时速度较慢

ios - 无法将 JSONValue 写入 NSDictionary - JSON 框架无法正常工作

android - 手机右侧的空白

swift - Swift 中的事件指示器表格 View

ios - 为 UILocalNotification 启用 TTS

ios - 容器 View 中的数据仅传递给子 VC 一次

ios - 在两个 UIViewControllers 的 View 之间滑动

ios - 在其父类(super class)初始化之后初始化 UIView init?

ios - 如何移动 UIButton