我希望在UIButton上有某种形式的脉冲动画(无限循环“缩放”),这样它就能立即引起用户的注意。
我看到了这个链接How to create a pulse effect using -webkit-animation - outward rings,但我想知道是否有任何方法可以只使用本机框架来做到这一点?
发布于 2014-12-08 18:53:00
下面是它的快速代码;)
let pulseAnimation = CABasicAnimation(keyPath: "transform.scale")
pulseAnimation.duration = 1.0
pulseAnimation.fromValue = NSNumber(value: 0.0)
pulseAnimation.toValue = NSNumber(value: 1.0)
pulseAnimation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
pulseAnimation.autoreverses = true
pulseAnimation.repeatCount = .greatestFiniteMagnitude
self.view.layer.add(pulseAnimation, forKey: nil)
发布于 2015-08-05 18:04:08
swift代码缺少一个fromValue
,我必须添加它才能使其正常工作。
pulseAnimation.fromValue = NSNumber(value: 0.0)
此外,还应设置forKey
,否则removeAnimation
将不起作用。
self.view.layer.addAnimation(pulseAnimation, forKey: "layerAnimation")
发布于 2016-06-10 03:50:19
func animationScaleEffect(view:UIView,animationTime:Float)
{
UIView.animateWithDuration(NSTimeInterval(animationTime), animations: {
view.transform = CGAffineTransformMakeScale(0.6, 0.6)
},completion:{completion in
UIView.animateWithDuration(NSTimeInterval(animationTime), animations: { () -> Void in
view.transform = CGAffineTransformMakeScale(1, 1)
})
})
}
@IBOutlet weak var perform: UIButton!
@IBAction func prefo(sender: AnyObject) {
self.animationScaleEffect(perform, animationTime: 0.7)
}
https://stackoverflow.com/questions/8083138
复制相似问题