Wednesday, 21 August 2013

Number increment animation while scrolling ios

Number increment animation while scrolling ios

I have a UILabel which will contain a number that needs to be animated to
increment to a given value from zero. The label is placed inside an
UITableView and is subview of an UITableViewCell. For some weird reason my
numbers wont animate while the view is scrolling. If I pause the scrolling
numbers animate. Why is that so and how to fix it?
Approach 1 which fails:
NSInteger fromValue = 0;
NSInteger toValue = 57; //In this example toValue has to be greater than
fromValue
NSString *suffix = @"K";
NSTimeInterval interval = 0.016; //Adjust for different animation speed
NSTimeInterval delay = 0.0;
for (float i = fromValue; i <= toValue; i++)
{
NSString *labelText = [NSString stringWithFormat:@"%0.3f%@", i, suffix];
[numberLabel1 performSelector:@selector(setText:) withObject:labelText
afterDelay:delay];
delay += interval;
}
The second one was to use UICountingLabel from Giuthub which offers the
same functionality but also doesnt work. Why? How to fix? My code of using
it looks like:
UICountingLabel *numberLabel1 = [[UICountingLabel alloc]
initWithFrame:CGRectMake(0, 105, winSize.width / 2, 40)]; //winSize is
numberLabel1.textAlignment = NSTextAlignmentCenter;
numberLabel1.method = UILabelCountingMethodLinear;
numberLabel1.format = @"%.3f";
[numberLabel1 countFrom:0 to:num1.floatValue withDuration:countDuration];
Any other way on how to make this "tick"? I need this animation to be able
to scroll really badly.
Cheers, Jan.

No comments:

Post a Comment