UIBezierPath:如何使用 - (BOOL)containsPoint:(CGPoint)指向onPath:(UIBezierPath *)路径inFillArea:(BOOL)inFill方法填充图像?

时间:2013-09-24 12:07:23

标签: ios cocoa-touch cocos2d-iphone touch uibezierpath

我有一张图片.PNG(例如只有黑色轮廓的动物图片),我想在iPad屏幕上通过触摸填充渐变。

我正在从这里关注Apple的指南

http://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html

遵循Apple的指南:

- (BOOL)containsPoint:(CGPoint)point onPath:(UIBezierPath *)path inFillArea:  
   (BOOL)inFill {

NSLog(@"contains point Path %@", path);
NSLog(@"Touch point %f %f", point.x, point.y );

CGContextRef context = UIGraphicsGetCurrentContext();
CGPathRef cgPath = path.CGPath;
BOOL    isHit = NO;
// Determine the drawing mode to use. Default to detecting hits on the stroked     
  portion of the path.
CGPathDrawingMode mode = kCGPathStroke;

if (inFill) { // Look for hits in the fill area of the path instead.
    if (path.usesEvenOddFillRule)
        mode = kCGPathEOFill;
    else
        mode = kCGPathFill;
}

 // Save the graphics state so that the path can be removed later.

CGContextSaveGState(context);

 CGContextAddPath(context, cgPath);

// Do the hit detection.
isHit = CGContextPathContainsPoint(context, point, mode);

CGContextRestoreGState(context);

return isHit; }

我只是想知道如何在我的应用中使用此方法。

告诉我这是为了什么步骤?

我是新手,请帮助我......

0 个答案:

没有答案