首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在UIButton - iOS上制作原生“脉冲效果”动画

如何在UIButton - iOS上制作原生“脉冲效果”动画
EN

Stack Overflow用户
提问于 2011-11-11 00:46:33
回答 3查看 66.2K关注 0票数 90

我希望在UIButton上有某种形式的脉冲动画(无限循环“缩放”),这样它就能立即引起用户的注意。

我看到了这个链接How to create a pulse effect using -webkit-animation - outward rings,但我想知道是否有任何方法可以只使用本机框架来做到这一点?

EN

回答 3

Stack Overflow用户

发布于 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)
票数 33
EN

Stack Overflow用户

发布于 2015-08-05 18:04:08

swift代码缺少一个fromValue,我必须添加它才能使其正常工作。

pulseAnimation.fromValue = NSNumber(value: 0.0)

此外,还应设置forKey,否则removeAnimation将不起作用。

self.view.layer.addAnimation(pulseAnimation, forKey: "layerAnimation")
票数 11
EN

Stack Overflow用户

发布于 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)
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8083138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档