【问题标题】:Swift Scale Animation is not animating viewSwift Scale Animation 不是动画视图
【发布时间】:2021-01-25 12:51:33
【问题描述】:

我只想拥有一个pulsating UIView。为此我设置了这个:

let highlightView: UIView = {
    let v = UIView()
    v.translatesAutoresizingMaskIntoConstraints = false
    v.backgroundColor = .lightBlueCustom
    v.alpha = 0.9
    return v
}()

let scaleAnimation: CABasicAnimation = {
    let v = CABasicAnimation(keyPath: "transform.scale")
    v.duration = 0.5
    v.repeatCount = .infinity
    v.autoreverses = true
    v.fromValue = 1.0
    v.toValue = 1.4
    return v
}()

这就是我所说的:

func showHighlightView(viewToHighlight: UIView, height: CGFloat) {
    self.view.addSubview(highlightView)
    highlightView.heightAnchor.constraint(equalTo: viewToHighlight.heightAnchor).isActive = true
    highlightView.widthAnchor.constraint(equalTo: highlightView.heightAnchor).isActive = true
    
    highlightView.centerXAnchor.constraint(equalTo: viewToHighlight.centerXAnchor).isActive = true
    highlightView.centerYAnchor.constraint(equalTo: viewToHighlight.centerYAnchor).isActive = true
    highlightView.layer.cornerRadius = height/2

    highlightView.layer.add(self.scaleAnimation, forKey: "scale")

    self.view.bringSubviewToFront(viewToHighlight)
    self.view.bringSubviewToFront(highlightView)
}

func showWishIntro() {
    showHighlightView(viewToHighlight: self.addWishButton, height: 60)
}

但这不起作用。它正确显示highlightView,但没有动画。我在这里错过了什么?

【问题讨论】:

    标签: ios swift animation uiview


    【解决方案1】:

    好的,所以我修复了它...这只是一个幸运的猜测,但我现在在 viewDidLayoutSubviews 中调用 showWishIntro,但它并没有按预期工作。我不知道为什么,所以如果有人愿意解释,请告诉我:D 我很高兴它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      • 2018-02-12
      • 1970-01-01
      相关资源
      最近更新 更多