我有一个简单的闪烁动画数字分频器在数字时钟。视图层次结构如下所示:
当StartButton按下ClockView变得可见(它是结束按钮),并启动动画闪烁数字除法器每秒钟。但动画片开始几分钟后,就出现了闪烁的白线。你可以在这段视频中看到:
- (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还是一个特征?我做错了什么?
发布于 2013-04-29 15:37:28
这个问题可以通过两种解决办法来解决。
首先是: 我想在你的动画完成之前,定时器又被重复了一遍。基本上,你有两个动画,它们的持续时间都是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];
}];
}];
}我不确定,但是这个密码可以帮你.祝好运
https://stackoverflow.com/questions/16209458
复制相似问题