在 CorePlot DatePlot (iOS) 中使用 CPTAnnotation [英] Using CPTAnnotation in CorePlot DatePlot (iOS)

查看:24
本文介绍了在 CorePlot DatePlot (iOS) 中使用 CPTAnnotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用 CorePlot,我想在 plotSymbol 上显示注释.我在最新的CorePlot 0.9 版本的示例项目中没有找到任何代码.经过一些研究,我已经到了这一点:

I am Using CorePlot in my app, and I want to display a annotation over the plotSymbol. I haven't found any code in the sample projects of the latest 0.9 version of CorePlot. After some research i have come to this point:

- (void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
    CPTLayerAnnotation *annot = [[CPTLayerAnnotation alloc]initWithAnchorLayer:graph];
    CPTBorderedLayer * logoLayer = [[(CPTBorderedLayer *) [CPTBorderedLayer alloc] initWithFrame:CGRectMake(10,10,100,50)] autorelease]; 
    CPTFill *fillImage = [CPTFill fillWithImage:[CPTImage imageForPNGFile:@"whatEver!"]]; 
    logoLayer.fill = fillImage; 
    annot.contentLayer = logoLayer; 
    annot.rectAnchor=CPTRectAnchorTop;
    [graph addAnnotation:annot];
}

但它显然不起作用......有人可以帮助我吗?

But its obviously not working.... Can anybody help me?

我的目标是对选定的绘图符号进行注释,类似于 MKMapView 中的注释.

My goal is to get an annotation over the selected plot symbol, similar to annotations in MKMapView.

更新

这是一个 DatePlot,只是为了澄清事情,它在 x 轴上使用自 2001 年以来的时间间隔.

It is a DatePlot, just to clarify things and it is working with time intervals since 2001 on the x-axis.

推荐答案

在 Core Plot 示例应用程序中有几个这样的示例.绘图库应用程序(以及其他几个应用程序)中的梯度散点图使用此方法将文本标签附加到所选点.Mac 版 CPTTestApp 中的点选择演示使用第二个散点图在所选点上绘制十字准线.

There are several examples of this in the Core Plot example apps. The gradient scatter plot in the Plot Gallery app (and several other apps as well) use this method to attach a text label to the selected point. The point selection demo in the Mac version of CPTTestApp uses a second scatter plot to draw a crosshairs over the selected point.

记住也要在散点图上设置 plotSymbolMarginForHitDetection 属性.默认值为 0,这意味着您必须准确地击中点的中心才能注册触摸.

Remember to set the plotSymbolMarginForHitDetection property on the scatter plot, too. The default is 0, which means you have to hit the center of the point exactly to register a touch.

Core Plot 中有两种类型的注释.CPTLayerAnnotation 锚定到给定的核心动画层(在您的情况下为图形).CPTPlotSpaceAnnotation 锚定到绘图空间坐标(== 数据坐标).您在下面的评论听起来像是您想使用绘图空间注释而不是图层注释.

There are two types of annotation in Core Plot. A CPTLayerAnnotation is anchored to a given Core Animation layer (the graph in your case). A CPTPlotSpaceAnnotation is anchored to a plot space coordinate (== data coordinate). Your comment below makes it sound like you want to use a plot space annotation instead of a layer annotation.

这篇关于在 CorePlot DatePlot (iOS) 中使用 CPTAnnotation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆