iphone - 选择点倒置时 CorePlot 显示标注

标签 iphone ios graph uikit core-plot

我在我的 CPTScatterPlotDelegate 中实现了以下代码来显示标注气泡:

-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)plot.plotSpace;
    CPTGraph *graph = plot.graph;
    int yIdent = ((NSString*)plot.identifier).intValue;

    NSNumber *yVal = [[_dataRange yForIndex:index] objectAtIndex:yIdent-1];
    NSNumber *xVal = [_dataRange xForIndex:index];
    double doublePrecisionPlotPoint[2];//[x,y]
    doublePrecisionPlotPoint[0] = xVal.doubleValue;
    doublePrecisionPlotPoint[1] = yVal.doubleValue;
    CGPoint touchedPoint = [graph.defaultPlotSpace plotAreaViewPointForDoublePrecisionPlotPoint:doublePrecisionPlotPoint];

    if(_annotation)
        [_annotation dismissCalloutAnimated:YES];
    _annotation = [[SMCalloutView alloc] init];
    //todo appropriate units
    _annotation.title = [NSString stringWithFormat:@"%.2f kg", yVal.doubleValue];
    [_annotation presentCalloutFromRect:CGRectMake(touchedPoint.x, touchedPoint.y, 1, 1) inView:_view constrainedToView:_view permittedArrowDirections:SMCalloutArrowDirectionAny animated:YES];
}

_dataRange 只是一个保存我的数据的自定义类,_annotation 是我的标注的实例。

问题是我无法让标注的位置正常工作。如果我将 _view 设置为 ViewController.view,我会得到正确的标注,但在错误的位置,如下所示:

Clicked point in yellow

如果我将 _view 设置为 CPTGraphHostingView 而不是我得到正确的点,但标注似乎像这样翻转:

enter image description here

如何获得正确的绘图点坐标来显示标注?

最佳答案

您不应该向托管 View 添加任何 subview ——它在 iOS 上使用翻转变换,因此 Core Plot 可以在 iOS 和 Mac 之间共享绘图代码。

使用 -convertPoint:toView:-convertPoint:fromView: 方法将 touchedPoint 从宿主视图的坐标系转换为 ViewController.view坐标系。

关于iphone - 选择点倒置时 CorePlot 显示标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12302051/

相关文章:

iphone - 如何在 iphone 应用程序中捕捉 sigpipe?

iphone - Obj-C,货币值(value)与可用数量,发行

iphone - 渲染以 PC 浏览器为中心,但在 iphone 浏览器中不对齐

iOS PayUMoney SDK key 无效

algorithm - MST 的线性时间算法

iphone - 在 iOS 中使用 Core Data 更新记录

php - 正在更新Apple Wallet的通行证-无法提取存档

ios - WatchConnectivity 如何在多个 WKInterfaceController 之间共享 session ?

matlab - 使用幅度向量在极坐标中创建绘图

c++ - 如何高效地存储非常大的图空间并具有快速索引?