Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 检测CAShapeLayer的长压入列表_Ios_Swift_Uiview_Core Graphics - Fatal编程技术网

Ios 检测CAShapeLayer的长压入列表

Ios 检测CAShapeLayer的长压入列表,ios,swift,uiview,core-graphics,Ios,Swift,Uiview,Core Graphics,我有一个对象列表,这些对象在我的视图上有一个可见的CAShapeLayer internal class Line { var layer = CAShapeLayer() } 这些将显示在类型为UIView的对象上。在ui视图上我有一个长按手势识别器,它应该能检测到其中一个line.layer上的长按 这就是我得到的 @objc private func didLongPress(_ sender: UILongPressGestureRecognizer) { var se

我有一个对象列表,这些对象在我的视图上有一个可见的
CAShapeLayer

internal class Line {
    var layer = CAShapeLayer()
}
这些将显示在类型为
UIView
的对象上。在
ui视图上
我有一个长按手势识别器,它应该能检测到其中一个line.layer上的长按

这就是我得到的

@objc private func didLongPress(_ sender: UILongPressGestureRecognizer) {
    var selectedLine: Line?
    let touchPoint = sender.location(in: self)
    if sender.state == .began {
        for line in lines {
            if line.layer.contains(touchPoint) == true {
                print("true")
            } else {
                print("false")
            }

        }
    } else if sender.state == .changed {
        for line in lines {
            if line.layer.contains(touchPoint) == true {
                print("true")
            } else {
                print("false")
            }

        }

    } else if sender.state == .ended {
        for line in lines {
            if line.layer.contains(touchPoint) == true {
                print("true")
            } else {
                print("false")
            }

        }

    }
}
不用说,它只打印假的。有人知道吗


谢谢

在以下方面找到了解决方案:

line.layer.path?.boundingBox.contains(touchPoint)