0

在为我的 defaultPlotSpace 设置委托后,我使用 CPPlotSpaceDelegate 协议在 iOS 和以下方法上接收触摸:

- (BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event 
          atPoint:(CGPoint)point{

}

-(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceDraggedEvent:(id)event atPoint:(CGPoint)point{

   NSSet *allTouches = [event allTouches];
   UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
   UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

   /*
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)space;
    CPTScatterPlot *scatterPlot = [[[plotSpace graph] allPlots] objectAtIndex:0]; 
    CGPoint plotAreaPoint = [[plotSpace graph] convertPoint:point toLayer:scatterPlot];
    NSLog(@"PlotAreaPoint : %.1f, %.1f", plotAreaPoint.x, plotAreaPoint.y);
   */

}
-(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceUpEvent:(id)event atPoint:(CGPoint)point{
}

如何通过多次触摸获得“PlotAreaPoint”?有人请帮帮我吗?

4

1 回答 1

0

托管视图将忽略除捏手势外的多点触控事件。只有一次触摸的事件才会传递到图形,然后传递到绘图和绘图空间。

如果您需要以这种方式捕获多点触控事件,您可以更改-touchesBegan:withEvent:方法CPTGraphHostingView以传递所需的事件。该方法还展示了如何从事件中获取点并将其转换为正确的坐标系。

请注意,self在此代码中是托管视图,而不是绘图空间:

CGPoint pointOfTouch = [[[event touchesForView:self] anyObject] locationInView:self];
if ( !collapsesLayers ) {
    pointOfTouch = [self.layer convertPoint:pointOfTouch toLayer:hostedGraph];
}
else {
    pointOfTouch.y = self.frame.size.height - pointOfTouch.y;
}
于 2012-05-22T01:07:44.933 回答