touchesMoved touches.first!.view 保持不变,如果我将手指移出视图
touchesMoved touches.first!.view remains the same, if I move a finger out of view
我对 touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
功能有疑问。更具体地说 - touches.first!.view 属性。
我需要知道用户指向的视图标签。但是当我将手指拖出视图边界时,touches.first!.view 值不会改变。
这就是我正在做的:
我有这段代码可以打印出所选视图的标签和背景颜色:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
print("\(touches.first!.view!.backgroundColor), View tag: " + String(touches.first!.view!.tag))
}
但我希望打印出来的是 UIExtendedGrayColorSpace 1 1, View tag: 0
,但我得到的不是这个 <UIDynamicSystemColor: 0x600000820b40; name = systemGroupedBackgroundColor>, View tag: 5
。这意味着,即使我从一个视图拖动光标,我仍然会从 touches.first!.view
.
获得第一个单击的视图
如何获得当前选择的视图?
根据上面 Rob 的评论回答
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
if let touch = touches.first {
if ( !self.grayUIView.frame.contains(touch.location(in: self.grayUIView)) ){
return
}else {
//still in current view - process with your logic
}
}
}
我对 touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
功能有疑问。更具体地说 - touches.first!.view 属性。
我需要知道用户指向的视图标签。但是当我将手指拖出视图边界时,touches.first!.view 值不会改变。
这就是我正在做的:
我有这段代码可以打印出所选视图的标签和背景颜色:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
print("\(touches.first!.view!.backgroundColor), View tag: " + String(touches.first!.view!.tag))
}
但我希望打印出来的是 UIExtendedGrayColorSpace 1 1, View tag: 0
,但我得到的不是这个 <UIDynamicSystemColor: 0x600000820b40; name = systemGroupedBackgroundColor>, View tag: 5
。这意味着,即使我从一个视图拖动光标,我仍然会从 touches.first!.view
.
如何获得当前选择的视图?
根据上面 Rob 的评论回答
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
if let touch = touches.first {
if ( !self.grayUIView.frame.contains(touch.location(in: self.grayUIView)) ){
return
}else {
//still in current view - process with your logic
}
}
}