我有一个显示值的 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/