Ios 快速缩放动画未设置视图动画
我只想要一个Ios 快速缩放动画未设置视图动画,ios,swift,animation,uiview,Ios,Swift,Animation,Uiview,我只想要一个脉动UIView。为此,我设置了以下内容: let highlightView: UIView = { let v = UIView() v.translatesAutoresizingMaskIntoConstraints = false v.backgroundColor = .lightBlueCustom v.alpha = 0.9 return v }() let scaleAnimation: CABasicAnimation =
脉动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
,但没有动画。我在这里遗漏了什么?好的,所以我修复了它。。。这只是一个幸运的猜测,但我现在正在viewdilayoutsubviews
中调用showWishIntro
,它没有按预期工作。我不知道为什么,所以如果有人愿意解释,请让我知道:D我很高兴它能起作用