我正在制作一个UIButton动画,它沿着x轴移动,同时从初始大小缩放到原始大小。当我尝试下面的代码时,它没有移动到它应该去的地方,也没有扩展到它的原始大小。
这是我初始化按钮的代码:
_testBtn1.layer.anchorPoint = CGPointMake(0.5f, 0.5f);
scaleBtn = CGAffineTransformMakeScale(0.2, 0.2);
[_testBtn1 setTransform: scaleBtn];这是我的移动/平移和缩放代码:
CGAffineTransform translate = CGAffineTransformMakeTranslation(50.0f, 0.0f);
CGAffineTransform animate = CGAffineTransformConcat(scaleBtn, translate);
[_testBtn1 setTransform:animate];任何帮助,建议都将不胜感激。我是iOS..thanks新手!
发布于 2013-08-12 17:52:52
您可以只创建自定义类型UIButton (可以通过将类型更改为自定义来使用IB,也可以通过编程方式使用
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];//set the button's image with
[aButton setImage:[UIImage imageNamed:@"abc" forState:UIControlStateNormal];要移动它,只需正常设置其位置动画即可。
[UIView animateWithDuration:0.5 animations:^{aButton.center = newCenter;}];或
CGRect originalFrame = aButton.frame;
aButton.frame = CGRectMake(originalFrame.origin.x, originalFrame.origin.y, originalFrame.size.width, 0);
[UIView animateWithDuration:0.5 animations:^{aButton.frame = originalFrame;}];或重新创建此链接http://objectiveapple.blogspot.in/2011/10/23-quizapp-16-animate-scale-uibutton.html
发布于 2013-08-12 17:56:02
这应该很容易完成核心动画,看看最基本的一个CABasicAnimation
发布于 2016-11-28 16:34:10
一个简单的缩放(弹跳)动画,在swift中实现了完成处理程序。
希望它能以某种方式对你或其他人有所帮助。
viewToanimate.transform = CGAffineTransform(scaleX: 0.1, y: 0.1) UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 6.0, animations: { _ in viewToAnimate.transform = .identity }, completion: { _ in //Implement your awesome logic here. })
https://stackoverflow.com/questions/18183956
复制相似问题