Ios 如果UITableView轻轻滚动,则动画可以工作,而不是';快速滚动时无法工作
我正在使用以下代码闪烁自定义Ios 如果UITableView轻轻滚动,则动画可以工作,而不是';快速滚动时无法工作,ios,uitableview,uilabel,Ios,Uitableview,Uilabel,我正在使用以下代码闪烁自定义UITableViewCell中的标签: -(void) startBlinker { [self stopBlinker]; self.edgeCaseLabelTimer = [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(blinkEdgeCaseLabel) userInfo:nil repeats:YES]; [[NSRunLoop
UITableViewCell
中的标签:
-(void) startBlinker
{
[self stopBlinker];
self.edgeCaseLabelTimer = [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(blinkEdgeCaseLabel) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.edgeCaseLabelTimer
forMode:NSRunLoopCommonModes];
}
-(void) blinkEdgeCaseLabel
{
if (blinkCycle == 0)
{
[UIView transitionWithView:self.thisCustomCell.edgeCaseLabel duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.thisCustomCell.edgeCaseLabel.textColor = [UIColor clearColor];
} completion:nil];
blinkCycle = 1;
}
else if (blinkCycle == 1)
{
[UIView transitionWithView:self.thisCustomCell.edgeCaseLabel duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.thisCustomCell.edgeCaseLabel.textColor = [UIColor redColor];
} completion:nil];
blinkCycle = 0;
}
}
-(BOOL)topOrBottomCellIsVisible
{
NSArray *indexes = [self.myTableview indexPathsForVisibleRows];
for (NSIndexPath *index in indexes)
{
if (index.row == 0)
{
return YES;
}
if (index.row == detailFRC.fetchedObjects.count - 1)
{
return YES;
}
}
return NO;
}
我希望有更多优雅和现代的代码用于此,但它是有效的。至少只要我不用力滚动电视,它就能工作。轻轻地,工作很好。快速,标签保持(静止时)在一个(或另一个)状态,并且不会闪烁
唯一受影响的单元格是顶部和底部单元格(这是唯一带有闪烁标签的单元格,并非巧合)
我试过使用ScrollViewDiEndScrollingAnimation
和ScrollViewDiEndDecelling
再次启动它,但没有骰子
有什么想法吗
注意:我在模拟器上测试,而不是在设备上
编辑:
根据@Woodstock的建议,我换成了一个普通的NSTimer。此外,我还加入了以下代码:
-(void) startBlinker
{
[self stopBlinker];
self.edgeCaseLabelTimer = [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(blinkEdgeCaseLabel) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.edgeCaseLabelTimer
forMode:NSRunLoopCommonModes];
}
-(void) blinkEdgeCaseLabel
{
if (blinkCycle == 0)
{
[UIView transitionWithView:self.thisCustomCell.edgeCaseLabel duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.thisCustomCell.edgeCaseLabel.textColor = [UIColor clearColor];
} completion:nil];
blinkCycle = 1;
}
else if (blinkCycle == 1)
{
[UIView transitionWithView:self.thisCustomCell.edgeCaseLabel duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.thisCustomCell.edgeCaseLabel.textColor = [UIColor redColor];
} completion:nil];
blinkCycle = 0;
}
}
-(BOOL)topOrBottomCellIsVisible
{
NSArray *indexes = [self.myTableview indexPathsForVisibleRows];
for (NSIndexPath *index in indexes)
{
if (index.row == 0)
{
return YES;
}
if (index.row == detailFRC.fetchedObjects.count - 1)
{
return YES;
}
}
return NO;
}
来自@Devunwired,在其对的回答中提供。我把这个方法放在几个与显示和滚动相关的关键位置
现在情况似乎更稳定了,但我认为@Fahim Parkar可能在sim卡上运行,而不是在设备上运行。我说的是“更健壮”而不是“治愈”,因为虽然闪烁看起来更能抵抗快速滚动,但它仍然不会在相关单元格首次出现时自动启动。当我在设备上试用时,我将向您报告。在设备上检查。。。我相信它会正常工作我自己也在想。不过,我还没说到这一点——资源调配等等。谢谢!您正在将已计划的计时器添加到运行循环中。如果要手动添加到运行循环,则不应使用定时计时器。而是使用一个普通的nstimer。感谢两位评论者!请查看我的编辑上面的结果。