我正在使用CADisplayLink作为频闪计时器。一次运行多个CADisplayLinks?
我有2个CADisplayLinks:
的主要原因之一(这件事在此运行):
SMPTELink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onTick)];
SMPTELink.frameInterval = 1;
[SMPTELink addToRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
频闪一个(频闪当这只运行时):
strobeLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(toggleStrobe)];
strobeLink.frameInterval = 1;
[strobeLink addToRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
[strobeLink setPaused:YES]; // I setPaused:NO when using the strobe.
一次运行两个CADisplayLinks不好吗?有时我的频闪看起来并不像我认为的那样平滑。这里是我的toggleStrobe方法:
-(void)toggleStrobe {
if (!self.firstTimestampStrobe)
self.firstTimestampStrobe = strobeLink.timestamp;
NSTimeInterval elapsed = (strobeLink.timestamp - self.firstTimestampStrobe);
NSInteger frameNumber = (NSInteger)(elapsed * ((strobeValue*15)/255)) % 2;
if (frameNumber != self.lastFrameStrobe)
{
if (frameNumber == 1) {
UIColor *color = [[UIColor alloc] initWithRed: 0 green: 0 blue: 0 alpha: 1.0];
strobeBackground.backgroundColor = color;
} else {
UIColor *color = [[UIColor alloc] initWithRed: 0 green: 0 blue: 0 alpha: 0];
strobeBackground.backgroundColor = color;
}
self.lastFrameStrobe = frameNumber;
}
}
想通过一种方法将它整合到一个CADisplayLink中 - 效果很棒! – objectiveccoder001 2013-02-22 05:09:08
从API角度来看,通过检查其他人是否已经存在或不存在来增加复杂性是有意义的。 – hfossli 2013-12-09 19:15:15