I have a UIScrollView which contains any number of thumbnails that should detect the touch event, perform 3D transformation on themselves and call a delegate method.
The one problem I am unable to overcome is detecting which sublayer is being tapped. I am setting layer.name to an index count and the subclass of the UIScrollView does get the touch event. Now the last remaining obstacle is how to do a hitTest on the sublayers to get the name property and voila!
I was thinking of subclassing a UIView as the container of the CALayer and capturing the touch event that way. But I am hoping there might be a more economical way to determine the sublayer being touched.
The code I have been trying (in my UIScrollView subclass):
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if ([touches count] == 1) {
for (UITouch *touch in touches) {
CGPoint point = [touch locationInView:[touch view]];
CALayer *alayer = [self.layer hitTest:point];
if (alayer) NSLog(@"layer %@ touched",alayer.name);
else NSLog(@"layer not detected");
}
}
}
I am getting two compile errors. first a warning: no hitTest method found. and an error "request for member 'name' is something not a structure or union".