Animate UILabel text between two numbers?

后端 未结 6 694
遇见更好的自我
遇见更好的自我 2020-11-28 19:01

I\'m new to iPhone and Mac programming (developed for Windows before), and I\'ve got a question:

How do I animate the text property of an UILabel<

6条回答
  •  清酒与你
    2020-11-28 19:54

    I found a great engine for tweening values with a variety of different timing functions called PRTween. Install the classes and create some code along these lines:

    - (IBAction)tweenValue
    {
        [[PRTween sharedInstance] removeTweenOperation:activeTweenOperation];
        PRTweenPeriod *period = [PRTweenPeriod periodWithStartValue:0.0 endValue:100.0 duration:1.0];
        activeTweenOperation = [[PRTween sharedInstance] addTweenPeriod:period
                                                                 target:self
                                                               selector:@selector(update:)
                                                         timingFunction:&PRTweenTimingFunctionCircOut];
    }
    
    - (void)update:(PRTweenPeriod*)period
    {
        self.animatingView.center = CGPointMake(period.tweenedValue + 100.0, 200.0);
        self.valueLabel.text = [NSString stringWithFormat:@"%.2f", period.tweenedValue];
    }
    

    Works a treat for me. :)

提交回复
热议问题