【问题标题】:How to zoom graph, created with CGContextRef如何缩放图形,使用 CGContextRef 创建
【发布时间】:2015-07-15 11:00:47
【问题描述】:

我正在使用 CGContextRef 绘制折线图。我可以放大缩小这个图表以清楚地显示线条吗?

我正在使用此代码。

CGContextRef context=UIGraphicsGetCurrentContext();
CGContextBeginPath(context);

CGMutablePathRef path=CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, lastPointX, lastPointY);
CGPathAddLineToPoint(path, NULL, newPointX, newPointY);

CGContextAddPath(context, path);
CGContextSetLineWidth(context, lineWidth);
CGContextSetStrokeColorWithColor(context, lineColor);
CGContextStrokePath(context);
CGPathRelease(path);

if (isFilling) {
    CGMutablePathRef path=CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, newPointX, newPointY);
    CGPathAddLineToPoint(path, NULL, newPointX, self.bounds.size.height);
    CGPathAddLineToPoint(path, NULL, lastPointX, self.bounds.size.height);
    CGPathAddLineToPoint(path, NULL, lastPointX, lastPointY);
    CGPathCloseSubpath(path);

    CGContextAddPath(context, path);
    CGContextSetFillColorWithColor(context, fillingColor);
    CGContextFillPath(context);
    CGPathRelease(path);
}

注意:- 我不想缩放视图。我想重新绘制线条以清晰显示。

【问题讨论】:

    标签: ios objective-c core-graphics cgcontextref cgcontextdrawpath


    【解决方案1】:

    您必须在 UIScrollView 上绘制此图,或者您可以在 UIScrollView 上添加视图,然后您可以放大和缩小该图。 为此,您应该实现以下 UIScrollView 方法:

    - (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    }
    - (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    }
    

    您可以参考这个不错的教程:

    http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content

    它会告诉你实现以下方法:

    - (void)centerContentsOfScrollView:(UIScrollView *)scrollView
    {
    }
    - (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer
    {
    }
    - (void)scrollViewTwoFingerTapped:(UITapGestureRecognizer*)recognizer
    {
    }
    

    【讨论】:

    • 我不想缩放视图。我想重新绘制线条以清晰显示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 2020-05-23
    相关资源
    最近更新 更多