![](/img/trans.png)
[英]how to disregard touch events in topmost uiview when it is clear and a different uiview can handle them
[英]How to disregard events when other event is executed?
假设您正在观察一个经常更改的属性,例如,当队列低于阈值时应重新填充的队列?
queue.rac_valuesForKeyPath("count", observer: self)
.toSignalProducer()
.filter({ (queueCount: AnyObject?) -> Bool in
let newQueueCount = queueCount as! Int
return newQueueCount < 10
})
.on(next: { _ in
// Refilling the queue asynchronously and takes 10 seconds
self.refillQueue(withItemCount: 20)
})
.start()
当队列为空时,将触发下一个处理程序并填充队列。 在填充队列时,SignalProducer发送一个新的下一个事件,因为count属性更改为1 –一个又一个。 但是我不希望触发下一个处理程序。 相反,我希望每次队列低于该阈值时触发一次。
我怎样才能最好地做到这一点? 是否有任何有用的事件流操作? 有任何想法吗?
干杯,
杰拉多
我认为您可以在此处使用combinePrevios
运算符,因为它可以为您提供当前值和以前的值:
queue.rac_valuesForKeyPath("count", observer: self)
.toSignalProducer()
.combinePrevious(0)
.filter { (previous, current) -> Bool in
return previous >= 10 && current < 10
}
.on(next: { _ in
// Refilling the queue asynchronously and takes 10 seconds
self.refillQueue(withItemCount: 20)
})
.start()
另一种方法是在原始代码中的filter
之后添加skipRepeats()
,但我认为在这种特殊情况下combinePrevious
更加明确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.