我有一个显示值(例如“32039”)的UITextView。通常,在我的应用程序中,我会更改该数字的值,但希望对值的增加或减少进行动画处理。我想到的动画类似于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)];
}