ios – 如何在UIButton上实现本机“脉冲效果”animation
我想在UIButton上有一些脉冲animation(无限循环“缩放”),所以立即引起用户的注意。
我看到这个链接如何创build一个使用-webkitanimation – 脉冲效应向外环,但我想知道是否有任何方式只使用本机框架做到这一点?
任何帮助非常感谢 – 代码示例甚至更好;-)
CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"]; theAnimation.duration=1.0; theAnimation.repeatCount=HUGE_VALF; theAnimation.autoreverses=YES; theAnimation.fromValue=[NSNumber numberWithFloat:1.0]; theAnimation.toValue=[NSNumber numberWithFloat:0.0]; [theLayer addAnimation:theAnimation forKey:@"animateOpacity"]; //myButton.layer instead of
迅速
let pulseAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.opacity)) pulseAnimation.duration = 1 pulseAnimation.fromValue = 0 pulseAnimation.toValue = 1 pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) pulseAnimation.autoreverses = true pulseAnimation.repeatCount = .greatestFiniteMagnitude self.view.layer.addAnimation(pulseAnimation, forKey: "animateOpacity")
看到这篇文章
这是它的快速代码;)
let pulseAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.scale") pulseAnimation.duration = 1.0 pulseAnimation.toValue = NSNumber(value: 1.0) pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) pulseAnimation.autoreverses = true pulseAnimation.repeatCount = FLT_MAX self.view.layer.add(pulseAnimation, forKey: nil)
swift代码缺less一个fromValue
,我不得不添加它才能使它工作。
pulseAnimation.fromValue = NSNumber(float: 0.0)
还应该设置forKey
,否则removeAnimation
不起作用。
self.view.layer.addAnimation(pulseAnimation, forKey: "layerAnimation")
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) }
- 使用核心animation对图像进行sorting,接收内存警告
- 如何禁用CALayer隐式animation?
- 你如何翻转非全屏UIView的超级查看与圆angular?
- 使用CABasicAnimationanimation框架属性
- drawRect圆和animation大小/颜色
- 视网膜显示核心graphics的字体质量
- Swift 2 – performBatchUpdates – 在UICollectionView框架内部可视化的时候,一个接一个地animation单元格
- UITableViewCell的高度变化没有滚动
- iOS – 在UILabel或UITextView中animation文字大小的变化?