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];
}

Tuesday, March 21, 2017

Shake Effect on UITextField (Objective c)

4:20 AM Posted by CHANDAN MAKHIJA No comments
As you have observed in many applications and websites that when user enters wrong username or password, textfields start shaking. Which indicates that user has entered wrong username or password.
For this you have to add this method in UIUtils and pass UIView as a parameter in it.

Code:

+ (void) addShakeEffectOn:(UIView*) view
{
    CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ;
    anim.values = @[
                    [ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f) ],
                    [ NSValue valueWithCATransform3D:CATransform3DMakeTranslation( 5.0f, 0.0f, 0.0f) ]
                    ] ;
    anim.autoreverses = YES ;
    anim.repeatCount = 2.0f ;
    anim.duration = 0.07f ;
    
    [view.layer addAnimation:anim forKey:nil ] ;

}

Now call this method when user inputs wrong username or password.

Monday, March 20, 2017

Shrink Effect on UIButton (Objective C)

11:46 AM Posted by CHANDAN MAKHIJA No comments
If you want to give your application a good look, you can try with this cool animations. Which will make your app look creative and eye catching.
You only have to add this method into UIUtility class and pass the UIView as a parameter, which can be a UIButton or UIImageView etc.

Code:


+ (void) addShrinkEffectOn:(UIView*)myView 
{
    [UIView transitionWithView:myView duration:2.0 options:UIViewAnimationOptionTransitionNone animations:^(void)
     {
         CGRect newRect = myView.frame;
         CGPoint center= myView.center;
         
         newRect.size.width /= 5;
         
         myView.frame = newRect;
         myView.center = center;
         
     } completion:^(BOOL finished)
     {
         // task to be done after completion of animation
     }];

}

Now call this method on the click of a button. You will observe that when you will click on this button, its width starts reducing animatedly. As soon as the animation gets over a completion block will be called. Add rest of your code into that block which you want to perform on the click of a button.