小编Rav*_*nne的帖子

如何在swift中为UILabel中的递增数设置动画

我有一个标签显示一个数字,我想将其更改为更高的数字,但是,我想为它添加一些耀斑.我想通过一个易于进出的曲线将数字增加到更高的数字,以便加速然后减慢速度.请问,如何在swift中实现这一点,这是我的代码.谢谢.

 let newValue : Double = 1000 
 let oldValue : Double = 500 

 timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: Selector("countAnimation:"), userInfo: ["oldValue":oldValue, "newValue": newValue],  repeats: true)

func countAnimation(timer: NSTimer)
{
    let dict = timer.userInfo as? [String:AnyObject]
    var OldTotalValue : Double = (dict!["oldValue"] as? Double)!
    let newTotalValue : Double = (dict!["newValue"] as? Double)!

    OldTotalValue = OldTotalValue + 10


    if newTotalValue < OldTotalValue
    {
        timer.invalidate()
    }
  else

    {
         mylabel.text =  String(OldTotalValue)
    }
}
Run Code Online (Sandbox Code Playgroud)

nstimer uianimation swift2 xcode7.1 ios9.2

7
推荐指数
1
解决办法
2054
查看次数

标签 统计

ios9.2 ×1

nstimer ×1

swift2 ×1

uianimation ×1

xcode7.1 ×1