ios - 动画 UITextView 增加或减少数字的值

标签 ios objective-c animation core-animation uitextview

我有一个显示值的 UITextView(例如“32039”)。在我的应用程序中,我经常更改该数字的值,但希望为值的增加或减少设置动画。我想到的动画类似于 this .我看过this问题,但使用答案中描述的方法唯一可能的动画是淡入/淡出、从左/右/下/上移入和显示/插入。是否有此动画的 UIKit 或 Core Animation 实现,甚至是第 3 方库中的实现,还是我应该自己推出?

最佳答案

//这样的东西会起作用

@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)];
}

关于ios - 动画 UITextView 增加或减少数字的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18807849/

相关文章:

objective-c - 如何使用 block 完成处理程序实现类方法

objective-c - 使用 like 选择查询以避免使用 fmdb 时的 SQL 注入(inject)

ios - 使用自定义消息处理错误?

objective-c - 使用 iOS NSRegularExpression 的 Ruby 风格字符串插值

ios - 在 Web View 中生成 PDF 时,如何先将 PDF 数据写入文件

android - Ping 应用程序动画 Android

java - SplashScreen java 更改 alpha

ios - 在 swift/objective-c 中将任意二进制数据编码/解码为字符串

ios - 无法更改从 xib 加载的 UIView 的大小和位置

swift - 以随机延迟(一个接一个)和随机水平位置动画滚动图像