CorePlot学习六---点击scatterPlot中的symbol点时弹出对应的凝视
因为项目须要用到用户点击 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搞定
其它的看凝视。不想再多加说明了
CorePlot学习六---点击scatterPlot中的symbol点时弹出对应的凝视的更多相关文章
- 解决Windows Server2008 R2中IE开网页时弹出阻止框
使用Windows Server2008,用IE打开网站时会弹出“Internet Explorer增强安全配置正在阻止来自下列网站的此应用程序中的内容”的对话框.如下图所示: 2011-10-14_ ...
- 解决Windows Server2008 R2中IE开网页时弹出阻止框(Windows Server2008网页无法打开的问题)
相信使用Windows Server2008的朋友都遇到过这种情况,用IE打开网站时会弹出“Internet Explorer增强安全配置正在阻止来自下列网站的此应用程序中的内容”的对话框.如下图所示 ...
- 解决eclipse中运行web项目时弹出的"Port 8080 required by Tomcat 9.0 Server at localhost is already in use...
1.tomcat默认端口是8080,可以修改通过tomcat的端口 修改tomcat\conf\server.xml 结果运行程序,还是报"Port 8080 required by ...
- EBS OAF开发中实现參数式弹出窗体
EBS OAF开发中实现參数式弹出窗体 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 概览 參数式弹出窗体和嵌入式弹出窗体不一样,它拥有独立 ...
- (原)android的alertdialog中加入edittext但是不弹出软键盘等问题的解决与原因
摘要:alertdialog中加入edittext但是不弹出软键盘等问题网上有很多不管用的解决方案, 本文意在给出更有效的解决办法,并初步探究其原因 正文 在对话框中插入文本框是十分常见的需求 通常我 ...
- 禁止手机页面中A标签长按弹出路径框
//禁止手机页面中A标签长按弹出路径框 window.onload=function(){ document.documentElement.style.webkitTouchCa ...
- Android定位&地图&导航——基于百度地图,实现自定义图标绘制并点击时弹出泡泡
一.问题描述 上一次我们使用百度地图实现基本的定位功能,接下来我们继续实现搜索和定位,并使用LocationOverlay绘制定位位置,同时展示如何使用自定义图标绘制并点击时弹出泡泡 如图所示: 二. ...
- 设置电脑中的某个程序不弹出UAC用户控制提示的方法
有用户发现在电脑开机后总是会弹出UAC用户账户控制窗口,这是因为电脑中的某个程序设置了开机启动,这样就会在开机后启动该程序时出现UAC提示.如果想要省略该提示,可以在电脑中设置该程序不弹出UAC用户控 ...
- VS2015+OpenGL4.0开发编译时弹出错误:glaux.lib(tk.obj) : error LNK2019: 无法解析的外部符号 _sscanf,该符号在函数 _GetRegistrySysColors@8 中被引用
一.问题描述: VS2015+OpenGL4.0开发编译时弹出如下所示的错误: 1>glaux.lib(tk.obj) : error LNK2019: 无法解析的外部符号 _sscanf,该符 ...
随机推荐
- like
5.在WHERE中使用like做模糊查询 %符号表示0到多个任意字符 _符号表示1个任意字符 //查询名字中含有O字符的员工信息 select empno,ename fr ...
- 2015 Multi-University Training Contest 5 hdu 5348 MZL's endless loop
MZL's endless loop Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- shareSDK的初步使用(shareSDK中微信、qq等兼容问题,以及cocoapods支持架构冲突问题的解决)
第一次使用shareSDK来做第三方分享,可是.昨天一天都是在调试bug,一直错误不断! 先说下我的开发环境: xcode:5.1 真机调试:iPhone5s 我们都知道xcode5.1以后開始是支持 ...
- HTML5中x-webkit-speech语音输入功能
如今各大站点都在搜索框中增加了语音输入功能,只是眼下仅仅有Chrome 11及以上版本号才支持. 能够用chrome浏览器在这里试试效果,点击话筒就可以: 实现起来也很easy,为input加入名为 ...
- [LeetCOde][Java] Best Time to Buy and Sell Stock III
题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...
- JAVA设计模式之【适配器模式】
适配器模式 当不需要实现一个接口所提供的所有方法时,可先设计一个抽象类该接口,并为接口每个方法提供一个默认实现 该抽象类的子类可以选择性地覆盖父类的某些方法来实现需求 角色 适配者接口 通常在接口中声 ...
- apiCloud实现加载更多效果,基本完美~
apiCloud实现加载更多效果 1.接口支持,加入参数page. $page = $this->_request('page','trim','1'); $pagesize = 10; // ...
- Elasticsearch yellow 意味着主分片可用,副本不可用
摘自:http://unasm.com/2016/11/644/ 在通过 /_cluster/state 命令查看es 状态的时候,发现es 处于一个yellow的状态, 这个很奇怪,按照官方的解释, ...
- 在vmware下为oracle RAC 创建共享存储的总结
首先,介绍下用命令行vm-diskmanager形式创建磁盘文件的方法(其实,图形界面添加新磁盘就是调用此命令). 很多网上文章提及plainmaker.exe去创建共享磁盘,是以前的版本 ...
- IDE-IntelliJ IDEA
IDE-IntelliJ IDEA 主题.字体.编辑区主题.文件编码修改.乱码问题 主题修改 上图标注 1 所示为 IntelliJ IDEA 修改主题的地方,可以通过打开左上角的File -> ...