Add comments
This commit is contained in:
parent
d29903d51b
commit
86581223ea
|
|
@ -4,6 +4,7 @@ open class RefreshControl: UIRefreshControl {
|
|||
private var action: Selector?
|
||||
private var target: NSObjectProtocol?
|
||||
|
||||
// Handle .valueChanged event of refresh control
|
||||
public override func addTarget(_ target: Any?, action: Selector, for controlEvents: UIControl.Event) {
|
||||
guard case .valueChanged = controlEvents else {
|
||||
return super.addTarget(target, action: action, for: controlEvents)
|
||||
|
|
@ -28,18 +29,22 @@ open class RefreshControl: UIRefreshControl {
|
|||
return super.sendActions(for: controlEvents)
|
||||
}
|
||||
|
||||
// Perform target's action
|
||||
if action != nil, target != nil {
|
||||
performRefreshAction()
|
||||
}
|
||||
}
|
||||
|
||||
open override func endRefreshing() {
|
||||
// Due to Apple's recommends
|
||||
CFRunLoopPerformBlock(CFRunLoopGetMain(), CFRunLoopMode.defaultMode.rawValue) {
|
||||
super.endRefreshing()
|
||||
}
|
||||
}
|
||||
|
||||
private func performRefreshAction() {
|
||||
// It is implemented the combined behavior of `touchUpInside` and `touchUpOutside` using `CFRunLoopPerformBlock`,
|
||||
// which `UIRefreshControl` does not support
|
||||
CFRunLoopPerformBlock(CFRunLoopGetMain(), CFRunLoopMode.defaultMode.rawValue) { [weak self] in
|
||||
guard let action = self?.action else {
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue