Core Plot范围改变性能

时间:2012-11-22 07:30:47

标签: ios performance drawing core-plot

我需要使用捏合识别器调整我的绘图大小,允许在左侧和底部的小区域中分别调整“宽度”和“高度”。 我的情节也在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图?

1 个答案:

答案 0 :(得分:0)

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