因为项目须要用到用户点击 symbol时,弹出对应的具体信息,发现国内解说的比較少,经过一番搜索验证最终解决,先看效果图:

详细须要改动的代码例如以下:

首先要引用托付方法:CPTScatterPlotDelegate、CPTPlotSpaceDelegate

完毕例如以下:

#pragma mark -
#pragma mark CPTPlotSpaceDelegate methods
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceCancelledEvent:(UIEvent *)event
{
return YES;
}
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceUpEvent:(UIEvent *)event atPoint:(CGPoint)point
{
return YES;
}
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDownEvent:(UIEvent *)event atPoint:(CGPoint)point
{
NSLog(@"you putdown at point:%@",[NSValue valueWithCGPoint:point]
);
return YES;
}
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDraggedEvent:(UIEvent *)event atPoint:(CGPoint)point
{
return YES;
} #pragma mark -
#pragma mark CPTScatterPlotDelegate
//当我们选择对应的点时。弹出凝视:
<span style="color:#FF0000;">-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)idx withEvent:(UIEvent *)event
{
</span> if ( symbolTextAnnotation ) {
[xyGraph.plotAreaFrame.plotArea removeAnnotation:symbolTextAnnotation];
symbolTextAnnotation = nil;
}
// Setup a style for the annotation
CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle];
hitAnnotationTextStyle.color = [CPTColor greenColor];
hitAnnotationTextStyle.fontSize = 10.0f;
hitAnnotationTextStyle.fontName = @"Helvetica-Bold"; // Determine point of symbol in plot coordinates
NSNumber *x =
[[datasForPlot objectAtIndex:idx] valueForKey:@"x"];
NSNumber *y = [[datasForPlot objectAtIndex:idx] valueForKey:@"y"];
NSString *date = [[datasForPlot objectAtIndex:idx]valueForKey:@"date"]; NSArray *anchorPoint = [NSArray arrayWithObjects:x, y, nil];
// Add annotation
// First make a string for the y value
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
NSString *yString = [formatter stringFromNumber:y];
NSString *myString = [NSString stringWithFormat:@"温度:%@\n日期:%@\n事件:%@",yString,date,nil]; // Now add the annotation to the plot area
CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:myString/*yString*/ style:hitAnnotationTextStyle];
symbolTextAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:xyGraph.defaultPlotSpace anchorPlotPoint:anchorPoint];
symbolTextAnnotation.contentLayer = textLayer;
symbolTextAnnotation.displacement = CGPointMake(0.0, 20.0);
[xyGraph.plotAreaFrame.plotArea addAnnotation:symbolTextAnnotation]; // NSLog(@"index:%lu,event:%@",(unsigned long)idx,event);
}

千万别忘记了依据自定义的设置对应的delegate = self;

红色标注的就是我们实现该功能的重点

对了。忘记说一点,该点很重要。不然你手指点击不灵活。我们的symbol那么小。还要点击到它的中心才干触发以下的方法,这多难啊,有个參数设置一下就搞定了,设置它的触发范围:

    CPTScatterPlot *boundLinePlot = [[CPTScatterPlot alloc]init];
boundLinePlot.<span style="color:#FF0000;">plotSymbolMarginForHitDetection</span> = 5.0f;//设置symbol点的外沿范围。以用来检測手指的触摸

ok搞定

其它的看凝视。不想再多加说明了

代码传送门:http://download.csdn.net/detail/u012951123/7521733

最新文章

  1. STM32 USB转串口驱动 Virtual COM Port Driver(V1.3.1)
  2. 描述了say_hello函数的具体内容,调用zend_printf系统函数在php中打印字符串
  3. C#通过存储过程进行查询
  4. ArcGIS Engine -- 常用方法
  5. sql表设计器的几个默认值
  6. D2 前端技术论坛总结(下)
  7. 【Java基础】增强for循环要注意陷阱
  8. QLibraryInfo
  9. shell脚本调用python脚本的路径问题
  10. CSS _text-align:justify;实现两端对齐
  11. Java变成思想--多线程
  12. mysql-tar包搭建过程
  13. Hbase 与mapreduce结合
  14. BZOJ1827[USACO 2010 Mar Gold 1.Great Cow Gathering]——树形DP
  15. windows系统安装完后要做的事情
  16. 使用echo $? 查看命令是否执行成功
  17. js设计模式总结3
  18. 洛谷P4219 [BJOI2014]大融合(LCT)
  19. ubuntu 的chmod 和 chown
  20. Qt Designer中文入门教程

热门文章

  1. js解决跨域问题
  2. js常用事件及事件对象
  3. SpringBoot中打包设置,将配置文件打包在外部
  4. Xshell 安装 Xftp
  5. jvm 堆、栈 、方法区概念和联系
  6. (转)彻底学会使用epoll(一)——ET模式实现分析
  7. ZOJ 3329
  8. crm操作报价单实体
  9. 【跟我一步一步学Struts2】——拦截器
  10. (转载) android项目大全,总有你所需的