IOS would like to ask CAShapeLayer to create a straight line. How to respond to gestures

CAShapeLayer plus UIBezierPath draws an oblique line. You can"t click on it. Ask the boss for advice

Jun.15,2022

on his parent view UIView, respond to the gesture.

because UIView can respond to events, CALayer cannot.

UIKit uses UIResponder as the response object to respond to and process events passed by the system. UIApplication, UIViewController, UIView, and all subclasses of UIView (including UIWindow) are responders responder, through inheritance.

the interface for handling various events and event delivery is defined in UIResponder, while CALayer inherits NSObject directly and has no corresponding interface for handling events.

on the official document, it is written very clearly

https://developer.apple.com/d...

0


Layer is designed not to respond to events, so you need to respond to events, handle them in the touch event in view, or add your own gestures

Menu