动画两个数字之间的UILabel的文本? [英] Animate UILabel text between two numbers?

查看:162
本文介绍了动画两个数字之间的UILabel的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的iPhone和Mac程序(之前为Windows开发的),我也有一个问题:

I'm new to iPhone and Mac programming (developed for Windows before), and I've got a question:

我如何动画文字属性的UILabel 两个数字之间,例如从 5 80 在渐出风格?是否有可能与 CoreAnimation
我正在寻找在谷歌一小时,但我还没有发现任何解决我的问题。
我想要什么:动画用户的钱一个简单的游戏。它看起来并不很漂亮,当它刚刚从云 50 100 或类似的东西没有动画。

How do I animate the text property of a UILabel between two numbers, e.g. from 5 to 80 in an Ease-Out style? Is it possible with CoreAnimation? I was searching on google for a hour, but I haven't found anything solving my problem. What I want: Animate the users money for a simple game. It doesn't look very nice when it just goes from 50 to 100 or something like that without animation.

有任何想法如何做到这一点?

Anyone having an idea how to do that?

谢谢!

推荐答案

您可以使用自动转换。它的工作得很好:

You can use the automatic transitions. It's working perfectly well :

// Add transition (must be called after myLabel has been displayed)
 CATransition *animation = [CATransition animation];
animation.duration = 1.0;
animation.type = kCATransitionFade;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[myLabel.layer addAnimation:animation forKey:@"changeTextTransition"];

// Change the text
myLabel.text = newText;

如果myLabel已经显示此code工作。如果不是myLabel.layer将零及动画将不被添加到对象

This code works if myLabel is already displayed. If not myLabel.layer will be nil and the animation will not be added to the object.

斯威夫特,这将是:

let animation: CATransition = CATransition()
animation.duration = 1.0
animation.type = kCATransitionFade
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
myLabel.layer.addAnimation(animation, forKey: "changeTextTransition")

这篇关于动画两个数字之间的UILabel的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆