1

我有数字时钟中数字分频器的简单闪烁动画。视图层次结构如下所示:

  • 时钟BGView
    • 开始按钮
    • 时钟视图

StartButton按下时ClockView变为可见(它在按钮上方)并开始每秒闪烁数字分隔符的动画。但动画开始几分钟后,出现闪烁的白线。你可以在这个视频中看到它:

https://dl.dropboxusercontent.com/u/1680228/ANIMATION_ARTEFACT.MOV

- (void)updateTimer {
     NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:self.timerStartDate];

    long seconds = lroundf(timeInterval); // Modulo (%) operator below needs int or long
    int hour = seconds / 3600;
    int mins = (seconds % 3600) / 60;

    self.clockHrsLabel.text = [NSString stringWithFormat:@"%02i", hour];
    self.clockMinLabel.text = [NSString stringWithFormat:@"%02i", mins];

    (hour > 0) ? (self.clockHrsLabel.alpha = 1.0f) : (self.clockHrsLabel.alpha = 0.2f);

    // devider animation blink
    [UIView animateWithDuration:0.3 animations:^{
        self.clockDeviderLabel.alpha = 1.0f;
    } completion:^(BOOL complete){
        [UIView animateWithDuration:0.3 animations:^{
            self.clockDeviderLabel.alpha = 0.0f;
        }];
    }]; 
}

它是错误还是功能?我究竟做错了什么?

4

1 回答 1

3

这个问题可以通过两种解决方案来解决..

第一个是:

我认为在您的动画完成之前再次重复计时器。基本上您有两个动画的持续时间均为 0.3 秒。所以你可以每 1 秒调用一次 timer 方法,因为总动画持续时间是 0.6

或者

第二个是:

不要使用计时器并使用以下代码....

- (void)updateTimer {
     NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:self.timerStartDate];

    long seconds = lroundf(timeInterval); // Modulo (%) operator below needs int or long
    int hour = seconds / 3600;
    int mins = (seconds % 3600) / 60;

    self.clockHrsLabel.text = [NSString stringWithFormat:@"%02i", hour];
    self.clockMinLabel.text = [NSString stringWithFormat:@"%02i", mins];

    (hour > 0) ? (self.clockHrsLabel.alpha = 1.0f) : (self.clockHrsLabel.alpha = 0.2f);

    // devider animation blink
    [UIView animateWithDuration:0.25 animations:^{
        self.clockDeviderLabel.alpha = 1.0f;
    } completion:^(BOOL complete){
        [UIView animateWithDuration:0.25 animations:^{
            self.clockDeviderLabel.alpha = 0.0f;
        } completion:^(BOOL complete){
            [self updateTimer];
        }];
    }]; 
}

我不确定,但这段代码可能会对你有所帮助.......祝你好运

于 2013-04-29T15:37:28.130 回答