0

我在这里使用代码的修改版本来显示来自图表中点的标注弹出窗口。我已经让它大部分工作了,但我遇到的问题是,当我滚动或缩放图形时,标注停留在屏幕上的同一位置,而不是随着点的移动而跟随。

如果您想要一些代码示例来玩,它们就在这里。关于如何使标注与情节点一起旅行的任何想法?谢谢!

-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)idx {
    if ([plot.identifier isEqual:_plotIdentifier]) {

        NSArray *selectedSymbolItem = [self.data.xyArrays objectAtIndex:idx];
        NSNumber *x = [selectedSymbolItem objectAtIndex:0];
        NSNumber *y = [selectedSymbolItem objectAtIndex:1];
        double doublePrecisionPlotPoint[2];
        doublePrecisionPlotPoint[0] = x.doubleValue;
        doublePrecisionPlotPoint[1] = y.doubleValue;
        CGPoint pointTouched = [plot.graph.defaultPlotSpace plotAreaViewPointForDoublePrecisionPlotPoint:doublePrecisionPlotPoint];

        CGPoint convertedPoint = [plot.graph convertPoint:pointTouched toLayer:self.view.layer];

        _popupView = [[SMCalloutView alloc] init];
        _popupView.title = [NSString stringWithFormat:@"Thing %i", idx];
        [_popupView presentCalloutFromRect:CGRectMake(convertedPoint.x, convertedPoint.y, 10, 10) inLayer:self.view.layer constrainedToLayer:self.hostView.layer permittedArrowDirections:SMCalloutArrowDirectionDown animated:YES];

    }
}
4

1 回答 1

1

使用绘图空间委托来监控绘图空间的变化并根据需要更新标注位置。

于 2013-02-08T01:59:05.063 回答