gpt4 book ai didi

ios - 检测 CAShapeLayer 列表中的长按

转载 作者:行者123 更新时间:2023-11-30 12:29:44 25 4
gpt4 key购买 nike

我有一个在我的 View 上具有可见 CAShapeLayer 的对象列表。

internal class Line {
var layer = CAShapeLayer()
}

这些显示在 UIView 类型的对象上。在 UIView 上,我有一个长按手势识别器,它应该检测到对其中一个 line.layers 的长按。

这就是我得到的

@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")
}

}

}
}

不用说,它只会打印 false。有人有什么主意吗?

谢谢!

最佳答案

找到解决方案:

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

关于ios - 检测 CAShapeLayer 列表中的长按,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43714508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com