Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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 在Swift中触摸移动时,如何检测新视图?_Ios_Swift_Xcode - Fatal编程技术网

Ios 在Swift中触摸移动时,如何检测新视图?

Ios 在Swift中触摸移动时,如何检测新视图?,ios,swift,xcode,Ios,Swift,Xcode,我想在触摸过程中检测新视图,当我的手指从一个视图移动到另一个视图时移动。我使用touch.first来检测它,但它显示一个视图,甚至我的手指也在触摸(推)b视图。 如何在touchedMoved中检测我正在触摸(推)哪个视图 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { let touch = touches.first! print(touch.view) //

我想在触摸过程中检测新视图,当我的手指从一个视图移动到另一个视图时移动。我使用touch.first来检测它,但它显示一个视图,甚至我的手指也在触摸(推)b视图。
如何在touchedMoved中检测我正在触摸(推)哪个视图

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first!
    print(touch.view) // return aView
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first!
    print(touch.view) // return aView even I'm touching bView from aView during this method
}
override func touchsbegind(touch:Set,带有事件:UIEvent?){
让我们先接触!
打印(touch.view)//返回视图
}
覆盖功能触摸移动(touchs:Set,带有事件:UIEvent?){
让我们先接触!
print(touch.view)//返回aView,即使在此方法中我正在从aView中触摸bView
}

如果您的
aView
bView
是同一
superview
的后代,并且它们的帧不相交,则可以使用以下代码:

let touchLocation = touch.location(in: superview)
if aView.frame.contains(touchLocation) {
    // touch in aView
} else if bView.frame.contains(touchLocation) {
    // touch in bView
}

从逻辑的角度来看,您可能希望通过一组触摸来检测它是否包含任何其他视图,但
aView
。使用first意味着您对发生的第一次触摸感兴趣,这基本上是
aView