触摸 CorePlot 中的绘图符号
当用户单击(或触摸)使用 Core Plot 创建的 mye 图表上的plotSymbol 时,我尝试运行一些代码。
这不适用于 scatterPlot:
-(void)scatterPlot:(CPScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex: (NSUInteger)index
{
NSLog(@"plotSymbolWasSelectedAtRecordIndex %d", index);
}
但是当我使用 barPlot 时效果很好:
-(void)barPlot:(CPBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
{
NSLog(@"barWasSelectedAtRecordIndex %d", index);
}
当用户单击或触摸我的 scatterPlot 时,我尝试捕获时缺少什么?
I'm trying to run some code when the user clicks (or touches) a plotSymbol on mye graph created with Core Plot.
This does not work with scatterPlot:
-(void)scatterPlot:(CPScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex: (NSUInteger)index
{
NSLog(@"plotSymbolWasSelectedAtRecordIndex %d", index);
}
But this works well when I use the barPlot:
-(void)barPlot:(CPBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
{
NSLog(@"barWasSelectedAtRecordIndex %d", index);
}
What's missing from my attempt to capture when the user clicks or touches on my scatterPlot?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在散点图上设置
plotSymbolMarginForHitDetection
。您应该将其设置为与绘图符号的大小相匹配,或者如果您需要单击更大的目标,则应将其设置为稍大一些。You need to set the
plotSymbolMarginForHitDetection
on your scatter plot. You should set it to match the size of your plot symbols or slightly larger if you need a bigger target to click.另外,不要忘记将 CPScatterPlot 的委托设置为指向您的对象,否则它不会被调用。
Also, don't forget to set the CPScatterPlot's delegate to point to your object, or it won't get called.
如果您在初始化时在 CPTGraphHostingView 的子类中设置您的内容(例如在来自 xib 的 initWithCoder 中),您的 HostedGraph 属性可能会被 Core Plot 破坏(至少从 1.3 开始),因此 Tap 处理会很短-电路。
https://code.google.com/p/core-plot /issues/detail?id=555
不用说,这发生在我身上:-) 我的解决方法是在我的 numberOfRecordsForPlot 中设置 HostedGraph(如果尚未设置)。
If you're setting up your stuff at init time in a subclass of CPTGraphHostingView (say in initWithCoder coming from a xib), your hostedGraph property might get clobbered by Core Plot (at least as of 1.3), and so the tap handling will short-circuit.
https://code.google.com/p/core-plot/issues/detail?id=555
Needless to say this happened to me :-) My workaround is to set the hostedGraph in my numberOfRecordsForPlot if it's not set already.