0

I have a subview over my view and i want this subview only to recognize pencil touch types. Every time the touch type is a finger i want it to be recognized by the parent view. Currently i am using the function shown below. The problem here is that the UIEvent has no touches so its not possible to check if it is a finger or pencil touch.

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    return false
}

1 Answers1

2

Update

One option would be disabling user interaction on the bottom view, and in the top view implementing:

func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent)
func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent)
func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent)

In these functions, you can check the type with touches.first?.type, and you can check the view with touches.first?.view, and if they satisfy your criteria you can call touchesBegan/Moved/Ended on the bottom view.

What it said before:

Use these three methods:

func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent)
func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent)
func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent)

You can check they type with touches.first?.type, and you can check the view with touches.first?.view.

You could forward the touches by calling touchesBegan/Moved/Ended on the view underneath.

Daniel
  • 3,188
  • 14
  • 34
  • Thats a good solution but my view is a UIScrollview. So when i pass tocuhesMoved nothing happpens ... – Filiprc Jul 30 '19 at 21:55
  • That's a complicated problem (UIScrollView with touchesMoved). Maybe [this](https://stackoverflow.com/questions/12259005/uiscrollview-with-touchesmoved-not-called) could help? – Daniel Jul 30 '19 at 22:10
  • Is there maybe a way that all my views detect touches and not only one ? – Filiprc Jul 30 '19 at 22:31
  • ScrollViews gobble up touches kind of obnoxiously. I think the solution I linked to in my last comment would help. An alternative (which I would do) is to have a simple view on top of the two views that manages all touches and forwards them to the appropriate view. – Daniel Jul 31 '19 at 13:26