I'm useing this code below to find a the layer that was pressed.
- (CALayer *)layerForTouch:(UITouch *)touch {
UIView *view = self.view;
CGPoint location = [touch locationInView:view];
location = [view convertPoint:location toView:nil];
CALayer *hitPresent开发者_Go百科ationLayer = [view.layer.presentationLayer hitTest:location];
if (hitPresentationLayer) {
return hitPresentationLayer.modelLayer;
}
return nil;
}
Everything works fine i Normal Portrait mode.
The problem is that if i rotate the view so i have it in landscape and pressing in top-middle of the screen, location will return 313, 543. X value should be 0 becouse it's top of the screen in landscape mode but it seems like this code dont remake the touchpoint depending on what orientation the user is currently in.
Any idea how to get the real touch point depending on the orientation?
I had a similar problem in a popover and I removed the line:
location = [view convertPoint:location toView:nil];
and it worked properly for me.
精彩评论