Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 核心图注释触摸事件_Ios_Objective C_Core Plot - Fatal编程技术网

Ios 核心图注释触摸事件

Ios 核心图注释触摸事件,ios,objective-c,core-plot,Ios,Objective C,Core Plot,我在应用程序中使用了核心图。 我需要使绘图的cptanotation对象响应用户的触摸事件。 正确的方法是什么?CPPlotSpaceDelegate协议用于设置delgate 您需要在视图控制器中调用下面的方法 -(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceUpEvent:(id)event atPoint:(CGPoint)point; -(BOOL)plotSpace:(CPPlotSpace *)spac

我在应用程序中使用了
核心图
。 我需要使绘图的
cptanotation
对象响应用户的触摸事件。
正确的方法是什么?

CPPlotSpaceDelegate
协议用于设置delgate

您需要在视图控制器中调用下面的方法

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

-(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceCancelledEvent:(id)event;

-(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point;

-(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceDraggedEvent:(id)event atPoint:(CGPoint)point;
对于注释点击,您需要这样使用

- (void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
NSLog(@"touch");
CPTGraph *graph = self.hostView.hostedGraph;

if (_annotation)
{
    [graph.plotAreaFrame.plotArea removeAnnotation:_annotation];
    _annotation = nil;
}

CPTMutableTextStyle *annotationTextStyle = [CPTMutableTextStyle textStyle];
annotationTextStyle.color = [CPTColor whiteColor];
annotationTextStyle.fontSize = 16.0f;
annotationTextStyle.fontName = @"Helvetica-Bold";

NSValue *value = [self.data objectAtIndex:index];
CGPoint point = [value CGPointValue];
NSString *number1 = [NSString stringWithFormat:@"%.2f", point.x];
NSString *number2 = [NSString stringWithFormat:@"%.2f", point.y];

NSLog(@"x and y are, %.2f, %.2f", point.x, point.y);
NSLog(@"number1 and number2 are, %.2f, %.2f", point.x, point.y);

NSNumber *x = [NSNumber numberWithFloat:point.x];
NSNumber *y = [NSNumber numberWithFloat:point.y];

NSArray *anchorPoint = [NSArray arrayWithObjects: x, y, nil];

NSString *final = [number1 stringByAppendingString:number2];
NSLog(@"final is %@",final);


CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:final style:annotationTextStyle];
_annotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
_annotation.contentLayer = textLayer;
_annotation.displacement = CGPointMake(0.0f, 0.0f);
[graph.plotAreaFrame.plotArea addAnnotation:_annotation];
}
CptAnotation包含contentLayer属性,属性类型为CPTLayer,SPTLayer确认接口CPTResponder

可以从以下位置创建内容层的自定义类和重写方法:


你好,Spynet,谢谢你的回复。但我想知道我们如何处理注释对象上的触摸事件。例如,如果我在那里有一个图像,我希望在用户点击它后执行一些操作。您的示例显示了如何在某些索引处处理对打印符号的触摸。CptAnotation对象是否有类似的委托方法?我可以使用CPPlotSpaceDelegate方法处理所有触摸事件,然后检查这些坐标是否有注释。但这似乎很棘手。我想这是一种优雅的方式。
cptanotation
定义了主机和内容层之间的关系。内容层可以是任何
CPTLayer
子类,所有这些子类都具有继承自
协议的事件处理方法。您可以为注释内容创建一个自定义的
CPTLayer
子类来处理事件,但是您还需要修改
CPTGraph
,以便它将事件传递给注释,以及已经传递给注释的绘图、绘图空间等。@EricSkroch,这是有意义的。您还可以解释如何强制
CPTGraph
对象将事件传递给注释吗?作为
cptanotationhostlayer
的子类,图形具有
annotations
属性,该属性包含附加到图形的所有注释。修改
-pointingDeviceDownEvent:atPoint:
和其他事件处理方法,以将事件传递到每个批注的内容层(如果该点位于内容
框架内)。
(BOOL)  - pointingDeviceDownEvent:atPoint:
(BOOL)  - pointingDeviceUpEvent:atPoint:
(BOOL)  - pointingDeviceDraggedEvent:atPoint:
(BOOL)  - pointingDeviceCancelledEvent: