iPhone hitTest broken after rotation

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2010-04-04T19:55:54Z Indexed on 2010/04/04 20:03 UTC
Read the original article Hit count: 679

Filed under:
|
|

Hi all,

I have a UIView that contains a number of CALayer subclasses. I am using the following code to detect which layer a touch event corresponds to:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self];
NSLog(@"%@,%@",NSStringFromCGPoint(point),[self.layer hitTest:point].name);


}

This works fine until the device is rotated. When the device is rotated all current layers are removed from the superlayer, and new CALayers are created to fit the new orientation. The new layers are correctly inserted and viewable in the correct orientation.

After the rotation the hitTest method consistently returns nil when clearly clicking on the newly created layers and registers for locations of layers which are incorrect. The coordinates of the hit test are correct, but no layers are found. Am I missing a function call or something after handling the rotation?

Cheers, Adam

© Stack Overflow or respective owner

Related posts about iphone

Related posts about core-animation