How to zoom graph, created with CGContextRef
Asked Answered
F

1

6

I am drawing a line graph by using CGContextRef. Can I zoom in zoom out this graph to show lines clearly.

I am using this code.

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);
}

Note:- I don't want to zoom view. I want to redraw lines to show clearly.

Flotow answered 15/7, 2015 at 11:0 Comment(0)
A
0

You have to draw this graph on UIScrollView or you can add view on UIScrollView then you can able to zoom in and out that graph. To do this you should implement following methods of UIScrollView:

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

For reference you can follow this nice tutorial:

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

which will tell you to implement following methods:

- (void)centerContentsOfScrollView:(UIScrollView *)scrollView
{
}
- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer
{
}
- (void)scrollViewTwoFingerTapped:(UITapGestureRecognizer*)recognizer
{
}
Aspic answered 15/7, 2015 at 11:11 Comment(1)
I don't want to zoom view. I want to redraw lines to show clearly.Flotow

© 2022 - 2024 — McMap. All rights reserved.