Possible duplicate:
How to verify that a user is connected to CGPath?
I follow the Apple manual here
http://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html
to try to detect a touch event only on the stroked part of my UIBezierPath. If I use the UIBezierPath, containsPoint method, it works fine, but it detects touch events on the bar and the fill part of UIBezierPath, and I want this to happen only on the stroked part.
Following Apple's guidance (in Listing 3-6 of the link), I created this function:
- (BOOL)containsPoint:(CGPoint)point onPath:(UIBezierPath*)path inFillArea:(BOOL)inFill { CGContextRef context = UIGraphicsGetCurrentContext(); CGPathRef cgPath = path.CGPath; BOOL isHit = NO;
When I call it, I get:
Error: CGContextSaveGState: invalid context 0x0
Error: CGContextAddPath: invalid context 0x0
Error: CGContextPathContainsPoint: invalid context 0x0
Error: CGContextRestoreGState: invalid context 0x0
Here is my view of drawRect, and my code to create my path:
- (UIBezierPath *) createPath { static UIBezierPath *path = nil; if(!path) { path = [[UIBezierPath bezierPathWithOvalInRect:CGRectMake(35, 45, 250, 250)] retain]; path.lineWidth = 50.0; [path closePath]; } return path; } - (void)drawRect:(CGRect)rect {
Then I try to call the containsPoint function inside touchphonesMoved, for example:
if (![self containsPoint:c onPath:[self createPath] inFillArea:NO]) return;
james source share