具有缩放功能的图表

时间:2017-03-25 20:49:04

标签: ios objective-c graph charts uiscrollview

我必须制作如下图:

enter image description here

以某种方式使用bezierPath,CAShapeLayer和动画我设法制作图表。但现在想要添加缩放功能。缩放代码如下:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _graphView;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollV withView:(UIView *)view atScale:(CGFloat)scale
{
    [_scrollView setContentSize:CGSizeMake(scale*320, scale*1700)];
}

当我水平滚动时,一切正常,但垂直方向请查看下图:

enter image description here

注意:X和Y轴在视图上,图形在滚动视图上,我还想根据缩放更改x和y坐标,并使其可滚动。任何帮助或建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

请参阅以下内容:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    CGFloat offsetX = MAX((scrollView.bounds.size.width - scrollView.contentSize.width) * 0.5, 0.0);
    CGFloat offsetY = MAX((scrollView.bounds.size.height - scrollView.contentSize.height) * 0.5, 0.0);

    _drawingView.center = CGPointMake(scrollView.contentSize.width * 0.5 + offsetX,
                                 scrollView.contentSize.height * 0.5 + offsetY);


    return _drawingView;
}