首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIView animateWithDuration伪像(在视图中闪烁白色垂直线)

UIView animateWithDuration伪像(在视图中闪烁白色垂直线)
EN

Stack Overflow用户
提问于 2013-04-25 08:05:10
回答 1查看 729关注 0票数 1

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

  • ClockBGView
    • StartButton
    • ClockView

StartButton按下ClockView变得可见(它是结束按钮),并启动动画闪烁数字除法器每秒钟。但动画片开始几分钟后,就出现了闪烁的白线。你可以在这段视频中看到:

ARTEFACT.MOV

代码语言:javascript
复制
- (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;
        }];
    }]; 
}

它是一个bug还是一个特征?我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-29 15:37:28

这个问题可以通过两种解决办法来解决。

首先是: 我想在你的动画完成之前,定时器又被重复了一遍。基本上,你有两个动画,它们的持续时间都是0.3秒。因此,您可以在每1秒之后调用timer方法,因为动画的总持续时间是0.6。

第二个是: 不要使用计时器,并使用以下代码..。

代码语言:javascript
复制
- (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];
        }];
    }]; 
}

我不确定,但是这个密码可以帮你.祝好运

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16209458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档