The*_*ude 3 xcode uiviewanimation ios swift
在社区的帮助下,我制作了一个按钮图像的放大和缩小动画.问题是,在第一次运行后,按钮被禁用,并且在重新启动应用程序之前不会再次工作.我想要的是,在单击按钮并完成动画后,它会返回起点,您可以再次单击它.这里的任何人可以帮助我吗?
@IBAction func coffeeButton(sender: UIButton) {
var timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "stopButtonAnimation", userInfo: nil, repeats: false)
let options = UIViewAnimationOptions.Autoreverse | UIViewAnimationOptions.Repeat | UIViewAnimationOptions.CurveEaseInOut
UIView.animateWithDuration(0.5, delay: 0, options: options, animations: {
self.button.transform = CGAffineTransformMakeScale(0.5, 0.5)
}, completion: nil)
}
func stopButtonAnimation(){
button.layer.removeAllAnimations()
}
Run Code Online (Sandbox Code Playgroud)
更正了你的stopButtonAnimation函数.
应用变换的作用是将按钮的比例设置为原始值,这样您就可以再次看到动画.
func stopButtonAnimation(){
button.layer.removeAllAnimations()
button.layer.transform = CATransform3DIdentity
}
Run Code Online (Sandbox Code Playgroud)
原始代码中的动画在比例值0.5处停止,因此下次单击按钮时,您看不到它(因为它的动画比例为0.5到0.5).
归档时间: |
|
查看次数: |
2116 次 |
最近记录: |