PDA

View Full Version : Trouble translating touch coordinate to CGContextRef in UIView




yoncopin
Jul 20, 2008, 03:53 PM
My IPhone app has a subclassed UIView being added to the main view to receive touch tap and drag events. A drag moves the subclassed UIView around the window, and a tap rotates it 45 degrees. Within the subclassed UIView I have used CoreGraphics path functions to draw a simple triangle.

My problem is that I would like to detect when the touch event has occurred only within the drawn triangle. I have the CGPoint which corresponds to the touch point for the entire device coordinate system and need to translate that point to the corresponding point on my graphics context within the UIView.

Originally I implemented my own translation function, which was able to successfully hit test using CGPathContainsPoint. Unfortunately once I rotate the UIView my function's limitations are reached and it seems like I'm trying to do this the hard way. I've experimented with CGContextConvertPointToUserSpace but it's results are not what I'd expect and I haven't been able to figure out how to use it properly yet.

Any help would be greatly appreciated.



yoncopin
Jul 21, 2008, 08:17 AM
Can anyone provide any insight on what the CGContextConvertPointToUserSpace and CGContextConvertPointToDeviceSpace do and how to interpret their results? I think these functions are the key to my problem, but I don't fully understand them.