Filiprc
Filiprc

Reputation: 1

How to pass touch event to other views only when touchtype is finger?

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
}

Upvotes: 0

Views: 578

Answers (1)

Daniel
Daniel

Reputation: 3597

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.

Upvotes: 2

Related Questions