当对象的属性isWorking设置为YES时,活动指示符应显示在屏幕上。此代码修复了以下问题:

[RACObserve(object, isWorking) subscribeNext:^(NSNumber *isWorking) {
  if ([isWorking boolValue]) {
    [activityIndicator startAnimating];
  }
  else {
    [activityIndicator stopAnimating];
  }
}];


除非经过一定的时间(例如1秒),否则如何防止信号触发。这将防止活动指示灯闪烁。

在这种情况下,节流不会这样做吗?

最佳答案

当isWorking等于YES时,我将包装原始信号以引入延迟。类似于以下内容。

RACSignal *isWorkingSignal = [[RACObserve(object, isWorking)
        map:^id(NSNumber *isWorking) {
            if (YES == [isWorking boolValue]) {
                NSTimeInterval delayInterval = 2; // seconds
                return [[RACSignal return:isWorking] delay:delayInterval];
            } else {
                return [RACSignal return:isWorking];
            }
        }] switchToLatest];

[isWorkingSignal subscribeNext:^(NSNumber *isWorking) {
    if (YES == [isWorking boolValue]) {
        [activityIndicator startAnimating];
    }
    else {
        [activityIndicator stopAnimating];
    }
}];

关于ios - 信号的宽限期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26221433/

10-14 19:54