这个可以吗?
- (RACSignal *)deferRefreshSignalUntilScrollViewIsNotBusy:(RACSignal *)infiniteSignal
{
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
__block BOOL disposed = NO;
RACDisposable *disposable = [infiniteSignal subscribeNext:^(id originalValue) {
dispatch_repeated(0.0, 0.5, dispatch_get_main_queue(), ^(BOOL *stop) {
BOOL scrollViewIsBusy = self.scrollView.isTracking
|| self.scrollView.isDecelerating
|| self.scrollView.isDragging
|| _flags.animatingArticlePageScroller;
*stop = disposed;
if(!scrollViewIsBusy)
{
[subscriber sendNext:originalValue];
*stop = YES;
}
});
}];
return [RACDisposable disposableWithBlock:^{
[disposable dispose];
disposed = YES;
}];
}];
}
static void dispatch_repeated_internal(dispatch_time_t firstPopTime, double intervalInSeconds, dispatch_queue_t queue, void(^work)(BOOL *stop))
{
__block BOOL shouldStop = NO;
dispatch_time_t nextPopTime = dispatch_time(firstPopTime, (int64_t)intervalInSeconds * NSEC_PER_SEC);
dispatch_after(nextPopTime, queue, ^{
work(&shouldStop);
if(!shouldStop)
{
dispatch_repeated_internal(nextPopTime, intervalInSeconds, queue, work);
}
});
}
void dispatch_repeated(double delay, double intervalInSeconds, dispatch_queue_t queue, void(^work)(BOOL *stop))
{
dispatch_time_t firstPopTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)delay * NSEC_PER_SEC);
dispatch_repeated_internal(firstPopTime, intervalInSeconds, queue, work);
}
重要的是不要一直轮询滚动视图值。仅在您现在有新值时进行轮询。