0

工作我做了一个自定义的UIControl它使用UIControlEvents来识别特定的相互作用。它的工作都很好。现在,我也希望我的UIControl来识别UIPanGestureRecognizer,这里的代码UIPanGestureRecognizer不UIControlEvents

fieldView.addTarget(self, action: #selector(willSelectField(sender:)), for: .touchDown) 
fieldView.addTarget(self, action: #selector(didSelectField(sender:)), for: .touchUpInside) 
fieldView.addTarget(self, action: #selector(canceledFieldSelection(sender:)), for: .touchUpOutside) 
fieldView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(draggingField(gesture:)))) 

所以,当我点击我的的FieldView(定制UIControl)touchDown将被识别。如果我不开始平移,touchUpInsidetouchUpOutside也将得到认可。但是,如果我和平移例如放开我的FieldView外,touchUpOutside不会被触发。


注:touchDragInside不是一个选择,因为它只能识别一个范围内的大约100像素内拖动。

回答

0

reference

如果一个手势识别器识别出它的姿态,视图的剩余触摸被取消。

你可以尝试设置cancelsTouchesInViewfalse,或覆盖在你的意见touchesCancelled(_:with:)

+0

我尝试过,但在'touchesCancelled'方法不会被调用,我也不能找到一种方法touchUpInside'或'touchUpOutside'之间'这个方法来区分 – Codey

相关问题