![](/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.