我一直在寻找,但还没有找到我需要的答案。
我有一个视图和它的子视图。在第二个视图中,根据给定的坐标创建CALayers。我想能够触摸任何一个CALayer并触发某些操作。
我找到了不同的代码片段,看起来可以帮助我,但我还没有能够实现它们。
例如:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if ([touches count] == 1) { for (UITouch *touch in touches) {
CGPoint point = [touch locationInView:[touch view]]; point = [[touch view] convertPoint:point toView:nil];
CALayer *layer = [(CALayer *)self.view.layer.presentationLayer hitTest:point];
layer = layer.modelLayer; layer.opacity = 0.5;
} } }
and also this....
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
// If the touch was in the placardView, bounce it back to the center
if ([touch view] == placardView) {
// Disable user interaction so subsequent touches don't interfere with animation
self.userInteractionEnabled = NO;
[self animatePlacardViewToCenter];
return;
}
}
我在这个领域还是一个新手,想知道如何做到这一点,有人可以告诉我吗?感谢任何帮助。