CorePlot学习六---点击scatterPlot中的symbol点时弹出相应的注释
2014-06-19 15:33
351 查看
由于项目需要用到用户点击 symbol时,弹出相应的详细信息,发现国内讲解的比较少,经过一番搜索验证终于解决,先看效果图:
具体需要修改的代码如下:
首先要引用委托方法:CPTScatterPlotDelegate、CPTPlotSpaceDelegate
完成如下:
红色标注的就是我们实现该功能的重点
对了,忘记说一点,该点非常重要,不然你手指点击不灵活。我们的symbol那么小,还要点击到它的中心才能触发下面的方法,这多难啊,有个参数设置一下就搞定了,设置它的触发范围:
CPTScatterPlot *boundLinePlot = [[CPTScatterPlot alloc]init];
boundLinePlot.<span style="color:#FF0000;">plotSymbolMarginForHitDetection</span> = 5.0f;//设置symbol点的外沿范围,以用来检测手指的触摸
ok搞定
其他的看注释,不想再多加说明了
代码传送门:http://download.csdn.net/detail/u012951123/7521733
具体需要修改的代码如下:
首先要引用委托方法: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
相关文章推荐
- CorePlot学习 点击scatterPlot中的symbol点时弹出相应的注释
- CorePlot学习六---点击scatterPlot中的symbol点时弹出对应的凝视
- 黑马程序员之WinForm编程基础学习笔记:用户在文本框1,2中输入两个数,点击按钮,在文本框3中显示从文本框1中的数字到文本框2中的数字之间的累加和。如果1或者2为错误的数据格式,则弹出对话框提示错
- IOS绘图控件Core-plot学习笔记
- CorePlot学习五----corePlot使用技巧及iOS内存优化之道
- CorePlot学习七---坐标轴的详细分析
- CorePlot学习零---安装
- 实现鼠标点击单元格显示...按钮,点击按钮,弹出对话框,选中后在相应的单元格显示Text,并绑定单元格Value值。
- [转载]core-Plot学习二 自定义CorePlot label及majorGridLine莫名其妙消失的Bug
- CorePlot学习三---自定义CorePlot label及majorGridLine莫名其妙消失的Bug
- CorePlot学习二---[深入浅出iOS库]之图形库CorePlot
- Core Plot学习笔记:绘制饼图
- VMWARE中虚拟工具VMTOOLS的安装 安装 vmtools之前,需要先打开虚拟机,并且启动其中的操作系统。 注意看下图中鼠标的位置。请将鼠标移动到相应位置上点击右键。 在弹出的菜单最下端点击“
- 学习笔记:点击网页的QQ超链接,马上弹出QQ聊天
- 点击每一个button,弹出相应的索引号
- CorePlot学习四--- 如何定制Core Plot主题
- JQuery学习之--4、点击弹出对话框
- 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码
- jQuery 学习笔记3 点击弹出一个div并允许拖拽移动
- CorePlot学习七---坐标轴的详细分析