动画一个UITextView增加或减少一个数字的值 [英] Animating a UITextView increasing or decreasing the value of a number

查看:192
本文介绍了动画一个UITextView增加或减少一个数字的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示的值一个UITextView(如32039)。经常在我的应用我改变这个数字的价值,但要进行动画的增加或减少的价值。动画我想到的是一样的东西这个。我见过<一个href=\"http://stackoverflow.com/questions/5301305/animate-uilabel-text-between-two-numbers/6267259#6267259\">this的问题,但使用中的答案中描述的方法的唯一的动画可能是进/出那些像褪色,在左/右/上/下移动,并且揭示/推。是否有一个的UIKit或核心动画实现这个动画,甚至是实施第三方库,或者我应该推出自己的?

I have a UITextView that displays a value (ex. "32039"). Frequently in my app I change the value of that number, but want to animate the increase or decrease in value. The animation I have in mind is something like this. I've seen this question but the only animations possible using the method described in the answers are those like fade in/out, move in from left/right/down/up, and reveal/push. Is there a UIKit or Core Animation implementation of this animation, or even an implementation in a 3rd party library, or should I roll my own?

推荐答案

//这样的事情会工作

// Something like this would work

@property (nonatomic, strong) UILabel *testLabel;

@property (nonatomic, strong) NSTimer *timer;

@property (nonatomic, assign) NSUInteger counter;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.testLabel = [[UILabel alloc] initWithFrame:CGRectMake(50.0f, 100.0f, 80.0f, 25.0f)];
    self.testLabel.text = @"44";
    [self.view addSubview:self.testLabel];

    self.timer = [NSTimer timerWithTimeInterval:.5 target:self selector:@selector(changeLabelText) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
    [self.timer fire];
}

- (void)changeLabelText {
    self.counter++;
    if (self.counter == 100000) {
         [self.timer invalidate];
    }

    self.testLabel.text = [NSString stringWithFormat:@"%d", (44 + self.counter)];
}

这篇关于动画一个UITextView增加或减少一个数字的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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