Swiftgram/Display/ViewControllerTracingNode.swift
2017-06-16 12:17:02 +03:00

35 lines
995 B
Swift

import Foundation
import AsyncDisplayKit
private final class ViewControllerTracingNodeView: UITracingLayerView {
private var inHitTest = false
var hitTestImpl: ((CGPoint, UIEvent?) -> UIView?)?
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if self.inHitTest {
return super.hitTest(point, with: event)
} else {
self.inHitTest = true
let result = self.hitTestImpl?(point, event)
self.inHitTest = false
return result
}
}
}
open class ViewControllerTracingNode: ASDisplayNode {
override public init() {
super.init(viewBlock: {
return ViewControllerTracingNodeView()
}, didLoad: nil)
}
override open func didLoad() {
super.didLoad()
(self.view as! ViewControllerTracingNodeView).hitTestImpl = { [weak self] point, event in
return self?.hitTest(point, with: event)
}
}
}