Wednesday, March 22, 2017

Pulse Effect (Objective C)

12:30 AM Posted by CHANDAN MAKHIJA No comments
As the name describes pulse effect works similar to movement of your pulse. You might have come accross this effect while recording a sound in many applications. For this just add the below method in UIUtils class and pass
UIView - on which you want to apply this effect
Size - size in float , to which extend you want the view to expand
Duration - time, how fast you want the animation to be performed

Code:

+ (void) addPulseEffectOn:(UIView*)view toSize:(float)value withDuration:(float)duration
{    
    CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    pulseAnimation.duration = duration;
    pulseAnimation.toValue = [NSNumber numberWithFloat:value];;
    pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulseAnimation.autoreverses = YES;
    pulseAnimation.repeatCount = FLT_MAX;
    
    [view.layer addAnimation:pulseAnimation forKey:nil];
} 

Now call this method in Life Cycle Method of View like 

Code:

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    [UIUtils addPulseEffectOn:self.pulseEffectView toSize:1.1 withDuration:1];
}

0 comments:

Post a Comment