iOS - CALayer and Gesture/Swipe Recognizer

2019-05-27 04:40发布

问题:

i added a layer to my view to create gradient background color, but i need to use UISwipeGestureRecognizer in my view. The problem is that now, with the layer, the swipe recognizer doesn't work! How can i do?? Can i add a swipe recognizer to a layer? Thanks

回答1:

CALayer and its children do not support UIGestureRecognizer's, only UIView does. This means that you must attach gesture recognizers to some enclosing view and call -[CALayer hitTest:], or -[CALayer pointInside:] to see which layer has been hit by a particular touch or event.