How to make native "Impulse Effect" animation on UIButton - iOS

I would like to have some kind of impulse animation (endless loop "scale to scale") on UIButton so that it immediately attracts the attention of users.

I saw this link. How to create a pulsed effect using -webkit-animation - outer rings, but I was wondering if there is a way to do this only using my own framework?

+83
ios objective-c iphone uikit animation
Nov 10 2018-11-11T00:
source share
4 answers
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 

swift

 let pulseAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.opacity)) pulseAnimation.duration = 1 pulseAnimation.fromValue = 0 pulseAnimation.toValue = 1 pulseAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) pulseAnimation.autoreverses = true pulseAnimation.repeatCount = .greatestFiniteMagnitude view.layer.add(pulseAnimation, forKey: "animateOpacity") 

See the article “Animating Layer Content”

+190
Nov 10 '11 at 16:50
source share

Here is a quick code for this;)

 let pulseAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.scale") pulseAnimation.duration = 1.0 pulseAnimation.toValue = NSNumber(value: 1.0) pulseAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) pulseAnimation.autoreverses = true pulseAnimation.repeatCount = .greatestFiniteMagnitude self.view.layer.add(pulseAnimation, forKey: nil) 
+26
Dec 08 '14 at 10:53 on
source share

The quick code is missing fromValue , I had to add it to make it work.

 pulseAnimation.fromValue = NSNumber(float: 0.0) 

forKey must also be set, otherwise removeAnimation does not work.

 self.view.layer.addAnimation(pulseAnimation, forKey: "layerAnimation") 
+8
Aug 05 '15 at 10:04
source share
 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) } 
+3
Jun 09 '16 at 19:50
source share



All Articles