4

ここで私のアプリでは、移動サブビューを使用しました。y= 150に達した場合、ジャンプ効果でボタンを作成したいので、このリンクを試して、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];  
}
}

ジャンプ効果(垂直)に変更するのを手伝ってください。

4

5 に答える 5

19

これを試して。ニーズに合わせて変更を加えることができます。

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

お役に立てれば。

于 2012-10-19T10:30:31.790 に答える
6

スウィフト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/

于 2017-10-02T15:19:03.770 に答える
4

このコードを試してください。

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

このリンクから全体の答えを参照してください

于 2012-10-19T06:20:08.943 に答える
0

そして、迅速なバージョン

    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)
    }
于 2015-08-22T09:17:49.057 に答える
0
UIView.animateWithDuration(0.1 ,
                               animations: {
                                self.buttonName.transform = CGAffineTransformMakeScale(1.3, 1.3)
        },
                                completion: { finish in
                                UIView.animateWithDuration(0.1){
                                self.buttonName.transform = CGAffineTransformIdentity
                                }
    })
于 2016-07-22T10:57:25.187 に答える