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?
Asked
Active
Viewed 436 times
1
-
I don't know of any 3rd party for that, there's certainly nothing in UIKit that does that. It's easy enough to do with a timer and a loop though. – rdelmar Sep 15 '13 at 02:12
1 Answers
2
// 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)];
}

newDeveloper
- 1,365
- 1
- 17
- 27