我Core Plot
在我的应用程序中使用。我需要使CPTAnnotation
绘图对象响应用户的触摸事件。这样做的正确方法是什么?
问问题
1864 次
2 回答
0
CPPlotSpaceDelegate
协议用于触摸事件设置委托
您需要在视图控制器中调用以下方法
-(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];
}
于 2013-04-03T13:58:52.910 回答
0
CPTAnnotation包含 contentLayer 属性,属性类型为CPTLayer,SPTLayer确认接口CPTResponder。
您可以为内容层创建自定义类并覆盖CPRResponder的方法:
(BOOL) - pointingDeviceDownEvent:atPoint:
(BOOL) - pointingDeviceUpEvent:atPoint:
(BOOL) - pointingDeviceDraggedEvent:atPoint:
(BOOL) - pointingDeviceCancelledEvent:
于 2016-05-10T11:24:07.753 回答