gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:29:05 26 4
gpt4 key购买 nike

我在我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com