0

我需要使用捏识别器调整我的绘图大小,它允许在左侧和底部的小区域中分别调整“宽度”和“高度”的大小。我的情节也在 UIScrollView 内部以水平滚动

这是我的 Y 轴捏代码:

- (void)yAxisPinchPerformed:(UIPinchGestureRecognizer *)pinchRecognizer
{
    CGFloat recognizerScale = pinchRecognizer.scale;

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotSpace;

    switch (pinchRecognizer.state) {
        case UIGestureRecognizerStateBegan:
        {
            _savedRange = plotSpace.yRange;
        }
            break;

        case UIGestureRecognizerStateChanged:
        {
            CGFloat scaledRange = recognizerScale * _savedRange;
            [plotSpace setYRange:scaledRange];
        }
            break;

        default:
            break;
    }
}

效果很好,但在设备上真的很慢,可能是因为它重绘了整个情节(它很宽并且在 UIScrollView 内部),而不仅仅是可见区域;我的情节包含最多 100 条渐变填充。我试图关闭填充,但它只起到了一点作用;

现在我有这些改进:

- (void)yAxisPinchPerformed:(UIPinchGestureRecognizer *)pinchRecognizer
{
    CGFloat recognizerScale = pinchRecognizer.scale;



    switch (pinchRecognizer.state) {
        case UIGestureRecognizerStateBegan:
        {
            // UIImageView *_imageView;
            [_imageView setImage:_graph.imageOfLayer];
            [_imageView setHidden:NO];
            // CGRect initialFrame is frame of graph container
            [_imageView setFrame:initialFrame];
            _savedHeigth = _imageView.frame.size.height;
        }
            break;

        case UIGestureRecognizerStateChanged:
        {
            CGFloat scaledHeight = recognizerScale * _savedHeight;

            CGRect imageFrame = _imageView.frame;
            imageFrame.size.height = scaledHeight;

            [_imageView setFrame:imageFrame];
        }
            break;

        case UIGestureRecognizerStateEnded:
            CGFloat scaledRange = calculateRangeFromHeights(...);

            CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotSpace;

            [plotSpace setYRange:scaledRange];
            [_imageView setHidden:YES];
            break;

        default:
            break;
    }
}

我得到绘图层的图像并执行 UIImageView 的缩放,它超级快。但是当我减小 Y 比例时,我只有部分图形,它在顶部被切割。

是否可以平滑实时地缩放 Core Plot 图?

4

1 回答 1

0

Core Plot 无法知道有多少图表在滚动视图中可见。我会删除滚动视图并依赖内置的 Core Plot 滚动。如果这不可行,您可以确定哪些条是可见的,并且只显示可见条。修改您的数据源以仅返回可见条的数据,并在可见条集更改时重新加载数据。

于 2012-11-22T13:36:45.720 回答