gpt4 book ai didi

ios - 如何快速知道一个水龙头是在 View 内还是在 View 外

转载 作者:IT王子 更新时间:2023-10-29 05:33:18 26 4
gpt4 key购买 nike

我正在尝试开发代码部分,以检查我的水龙头是在 View 内还是在 View 外,我尝试使用 pointInside 方法。如果 A 是主视图 Controller ,B 是 A 的 subview ,我如何才能知道用户在 B 中点击。

最佳答案

Apple 在Responder Chain 中解释得很好.您可以将以下功能添加到您的 View Controller :

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let firstTouch = touches.first {
let hitView = self.view.hitTest(firstTouch.location(in: self.view), with: event)

if hitView === viewB {
print("touch is inside")
} else {
print("touch is outside")
}
}
}

关于ios - 如何快速知道一个水龙头是在 View 内还是在 View 外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41674613/

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