开发者

Is there hitTest:(CGPoint) in CAShapeLayer?

开发者 https://www.devze.com 2023-01-30 17:47 出处:网络
I have a multiple CAShapeLayers in a view and I\'d like to drag it.(shape are irregular) Please give some sug开发者_运维知识库gestions for doing it.CALayer and its subclasses are not part of the respo

I have a multiple CAShapeLayers in a view and I'd like to drag it.(shape are irregular) Please give some sug开发者_运维知识库gestions for doing it.


CALayer and its subclasses are not part of the responder chain, and they do not descend from UIResponder. Therefore, touchesBegan:withEvent:, etc. will never be called on any CALayer subclass. You need to detect the touch on one of the hosting UIViews in the layer hierarchy. Then, you use hitTest: in the touch handlers to detect which layer was touched.

It will be easier on you if you create a UIView subclass with a CAShapeLayer as its backing layer like this:

@implementation MyShapeView

- (CALayer *)layerClass {
  return [CAShapeLayer class];
}

@end

Then, add instances of your custom view as subviews to your main view. After that, you can use the UIResponder methods or, even better, a UIGestureRecognizer to handle the dragging. I highly recommend using gesture recognizers if you can target iOS 3.2 or higher. They make event handling much simpler.

0

精彩评论

暂无评论...
验证码 换一张
取 消