简体   繁体   中英

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM