ios*_*dev 3 iphone uibutton uianimation ios
在我的应用程序中,我使用了移动子View.If它达到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];
}
}
Run Code Online (Sandbox Code Playgroud)
请帮我换成跳跃效果(垂直)?
小智 18
试试这个.您可以进行一些更改,以满足您的需求,
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];
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
斯威夫特 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)
}
Run Code Online (Sandbox Code Playgroud)
来源:http : //evgenii.com/blog/spring-button-animation-with-swift/