【问题标题】:Jumping effect on uibuttonsuibuttons的跳跃效果
【发布时间】:2012-10-19 06:08:12
【问题描述】:

在我的应用程序中,我使用了移动子视图。如果它达到 y=150,我想制作一个跳跃效果的按钮,我尝试了这个链接 adding bounce effect to appearance of UIImageView 它在水平方向上工作,我想要一个垂直方向,这是我的代码,

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

请帮我改成跳跃效果(垂直)?

【问题讨论】:

    标签: iphone ios uibutton uianimation


    【解决方案1】:

    试试这个。您可以进行一些更改以满足您的需要,

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

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      斯威夫特 3

      在这里,我找到了一篇关于这个有吸引力的流行动画的有用帖子。希望是你想要的

      @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)
      }
      

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

      【讨论】:

        【解决方案3】:

        试试这个代码..

        - (IBAction)bounce {
            CABasicAnimation *theAnimation;
            theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];///use transform
            theAnimation.duration=0.4;  
            theAnimation.repeatCount=2;
            theAnimation.autoreverses=YES;  
            theAnimation.fromValue=[NSNumber numberWithFloat:1.0]; 
            theAnimation.toValue=[NSNumber numberWithFloat:-20];
            [yourButton.layer addAnimation:theAnimation forKey:@"animateTranslation"];//animationkey    
        }
        

        查看this链接的完整答案

        【讨论】:

          【解决方案4】:

          还有 swift 版本

              func jumpButtonAnimation(sender: UIButton) {
                  let animation = CABasicAnimation(keyPath: "transform.scale")
                  animation.toValue = NSNumber(float: 1.3)
                  animation.duration = 0.1
                  animation.repeatCount = 0
                  animation.autoreverses = true
                  sender.layer.addAnimation(animation, forKey: nil)
              }
          

          【讨论】:

            【解决方案5】:
            UIView.animateWithDuration(0.1 ,
                                           animations: {
                                            self.buttonName.transform = CGAffineTransformMakeScale(1.3, 1.3)
                    },
                                            completion: { finish in
                                            UIView.animateWithDuration(0.1){
                                            self.buttonName.transform = CGAffineTransformIdentity
                                            }
                })
            

            【讨论】:

            • 您能否为您的答案添加一些解释?仅发布代码 sn-p 不是一个好方法。见How to ask
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-07-15
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-12-24
            • 2019-09-08
            相关资源
            最近更新 更多