【问题标题】:Animating a UITextView increasing or decreasing the value of a number动画 UITextView 增加或减少数字的值
【发布时间】:2013-09-15 00:47:24
【问题描述】:

我有一个显示值的 UITextView(例如“32039”)。我经常在我的应用程序中更改该数字的值,但想要动画增加或减少值。我想到的动画类似于this。我见过this 问题,但唯一可能使用答案中描述的方法的动画是淡入/淡出、从左/右/下/上移入和显示/推入。是否有此动画的 UIKit 或 Core Animation 实现,甚至是 3rd 方库中的实现,还是我应该自己推出?

【问题讨论】:

  • 我不知道有任何第三方可以做到这一点,UIKit 中肯定没有任何东西可以做到这一点。不过,使用计时器和循环很容易。

标签: ios objective-c animation core-animation uitextview


【解决方案1】:

// 这样的事情会起作用

@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)];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2013-04-03
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多