我是刚开始编程的,所以请原谅任何不清楚的地方。我试图使用animateWithDuration方法使我的一个按钮具有“闪烁效果”。目前,它的工作方式是“淡出”,其中按钮逐渐显示并每1秒消失一次(我将持续时间设置为1.0)。我希望降低动画的速度(不是持续时间,而是速度),这样动画效果就会发生得更突然。动画的间隔需要保持在每1秒。这有可能实现吗?我一直在研究,似乎animateWithDuration不允许这种规格.我需要通过另一种方法来处理这个问题吗?下面是我的代码。谢谢你的帮忙!顺便说一句,这都是在UIViewController in UIKit下完成的。
override func viewDidLoad() {
super.viewDidLoad()
self.tapButton.alpha = 0
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
UIView.animateWithDuration(1.0, delay: 0, options: .Repeat | .AllowUserInteraction | .Autoreverse, animations: { () -> Void in self.tapButton.alpha = 1.0
}, completion: nil )
}
发布于 2015-07-14 19:10:21
将动画放在1秒重复的NSTimer上,并减少动画的持续时间。
发布于 2015-07-14 19:10:20
尝试添加与曲线相关的选项:
UIViewAnimationOptions.CurveEaseOut
UIViewAnimationOptions.CurveEaseIn
UIViewAnimationOptions.CurveEaseInOut
是..as of 苹果文档
EaseInOut是一条轻松的曲线,它使动画开始缓慢,在持续时间的中间加速,然后在完成之前再次慢下来。这是大多数动画的默认曲线。 EaseIn是一条容易进入的曲线,它使动画开始缓慢,然后随着动画的发展而加速。 EaseOut是一条轻松曲线,它会使动画快速开始,然后在动画完成时减速。
因此,最后的结论如下:
UIView.animateWithDuration(1.0, delay: 0, options: .Repeat | .AllowUserInteraction | .Autoreverse | UIViewAnimationOptions.CurveEaseOut, animations: { [weak self] in
self?.tapButton.alpha = 1.0
}, completion: nil)
https://stackoverflow.com/questions/31414608
复制相似问题