Fix hit testing of text layers.

This commit is contained in:
Matthew Chen 2019-03-12 13:17:49 -04:00
parent 575de76a43
commit 2f7880af8e

View file

@ -642,10 +642,24 @@ public class ImageEditorCanvasView: UIView {
guard let sublayers = contentView.layer.sublayers else {
return nil
}
// First we build a map of all text layers.
var layerMap = [String: EditorTextLayer]()
for layer in sublayers {
guard let textLayer = layer as? EditorTextLayer else {
continue
}
layerMap[textLayer.itemId] = textLayer
}
// The layer ordering in the model is authoritative.
// Iterate over the layers in _reverse_ order of which they appear
// in the model, so that layers "on top" are hit first.
for item in model.items().reversed() {
guard let textLayer = layerMap[item.itemId] else {
// Not a text layer.
continue
}
if textLayer.hitTest(point) != nil {
return textLayer
}