【发布时间】:2012-03-14 00:37:57
【问题描述】:
我正在尝试检测用户是否点击了具有 CGContext 和如下路径的绘图中的图像(这发生在名为 SwbPlate 的 customview 类中:
SwbPlateImage * image;
CGFloat startAngle;
CGFloat endAngle;
CGContextRef context = UIGraphicsGetCurrentContext();
for (image in plateImages) {
endAngle = [EntGeometry pointToRadian:[image endPoint] withCenterPoint:CGPointMake(self.bounds.size.width/2 , self.bounds.size.height /2)];
startAngle = [EntGeometry pointToRadian:[image startPoint] withCenterPoint:CGPointMake(self.bounds.size.width/2 , self.bounds.size.height /2)];
imageToDraw = [image plateImg];
NSLog(@"%@", image);
CGContextSaveGState(context);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, self.bounds.size.width/2 , self.bounds.size.height/2);
CGPathAddArc( path,
NULL,
self.bounds.size.width/2,
self.bounds.size.height/2,
(self.bounds.size.width/2),
endAngle,
startAngle,
0);
CGPathCloseSubpath(path);
CGContextAddPath(context, path);
CGContextClip(context);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, [imageToDraw CGImage]);
CGContextRestoreGState(context);
//RVE MOD
image.imageContext = context;
然后我尝试查看用户是否在此上下文中的某个点上移动了触摸,但这似乎不起作用
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
NSArray *allTouches = [touches allObjects];
UITouch *touch = [allTouches objectAtIndex:0];
SwbDragProduct*dragProd;
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[SwbPlateView class]] &(CGRectContainsPoint([view frame], [touch locationInView:self.view])) ) {
NSLog(@" We touched in the PLATE");
for (SwbPlateImage *imgView in plateView.plateImages){
if(CGContextPathContainsPoint(imgView.imageContext, [touch locationInView:self.view],kCGPathFillStroke)){
NSLog(@" We Touched within the IMAGE");
}
}
}
【问题讨论】:
标签: iphone ios xcode cocoa-touch ipad