Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jumping effect on uibuttons

Here in my app i used the moving sub View.If it reach y=150,i want to make a buttons in jumping effect,i tried this link adding bounce effect to appearance of UIImageView it working in horizontal direction ,i want a vertical direction,Here my code,

-(void)godown 
 {
if (movingview.center.y < 150) movingview.center = CGPointMake(movingview.center.x, movingview.center.y +5);
if(movingview.center.y ==150)
{
  [UIView beginAnimations:@"bounce" context:nil];
  [UIView setAnimationRepeatCount:3];
  [UIView setAnimationRepeatAutoreverses:YES];  
  CGAffineTransform transform = CGAffineTransformMakeScale(1.3,1.3);
  bt1.transform = transform;
  bt2.transform=transform;
 [UIView commitAnimations];  
}
}

Please help me to change into jumping effect(vertically)?

like image 406
iosdev Avatar asked Nov 28 '22 11:11

iosdev


2 Answers

Try this. You can make some changes so it suits your need,

        CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];
        anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        anim.duration = 0.125;
        anim.repeatCount = 1;
        anim.autoreverses = YES;
        anim.removedOnCompletion = YES;
        anim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)];
        [senderView.layer addAnimation:anim forKey:nil];

Hope this helps.

like image 144
Mathew Varghese Avatar answered Dec 09 '22 15:12

Mathew Varghese


Swift 3

Here i found a useful post on this attractive pop animation. Hope it is what you want

enter image description here

@IBAction func btnCancel_click(_ sender: Any)
{
    btnCancel.transform = CGAffineTransform(scaleX: 0.50, y: 0.50)
    UIView.animate(withDuration: 2.0,
                   delay: 0,
                   usingSpringWithDamping: 0.2,
                   initialSpringVelocity: 6.0,
                   options: .allowUserInteraction,
                   animations: { [weak self] in
                    self?.btnCancel.transform = .identity
        },
                   completion: nil)
}

source: http://evgenii.com/blog/spring-button-animation-with-swift/

like image 30
Vaibhav Saran Avatar answered Dec 09 '22 15:12

Vaibhav Saran