我有一张竖起大拇指的图片。当用户点击它时,我会将图像倒置(就像大拇指向下(。然后,当他再次点击按钮时,我将其旋转回竖起大拇指的位置。但当图像旋转回竖起大拇指的位置时,它移动得非常快。我希望它在我给出的顺时针180位置的持续时间内。
我如何做的伪代码
@IBOutlet var likeButton: UIButton!
@IBOutlet var likeCountLabel: UILabel!
var counter = 0
var count = 10
@IBAction func likeButton(sender: UIButton)
{
let anim = CABasicAnimation(keyPath: "transform.rotation")
if counter == 0
{
anim.fromValue = M_PI
anim.toValue = 0
anim.additive = true
anim.duration = 0.50
likeButton.layer.addAnimation(anim, forKey: "rotate")
likeButton.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI))
count -= 1
likeCountLabel.text = "(count)"
counter = 1
}
else if counter == 1
{
anim.fromValue = M_PI
anim.toValue = 0
anim.additive = true
anim.duration = 0.50
likeButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI*2))
count += 1
likeCountLabel.text = "(count)"
counter = 0
}
在第二部分中,您错过了向按钮添加动画。
likeButton.layer.addAnimation(anim, forKey: "rotate")