Loquatious
Loquatious

Reputation: 1775

Need Infinite zooming for my Drawing View which is on UIscrollView

Is it possible to zoom infinite? as i have a floor drawing functionality, i need to zoom even for a small room to be display as larger by implementing infinite zooming. If i'm zooming more than 15 times of original drawing view, drawing is disappearing and displays nothing.

Any suggestions would be appreciated!!

Here is my sample code block:

self.scrView.maximumZoomScale=200;
self.scrView.minimumZoomScale=0.5;

#pragma mark ScrollView Deleagte

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.objDrawingView;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
[self.objDrawingView.layer setContentsScale:self.objDrawingView.transform.a*[[UIScreen mainScreen] scale]];
    [self.objDrawingView setNeedsDisplay];
}

Upvotes: 0

Views: 690

Answers (2)

robert
robert

Reputation: 2842

If you are doing the drawing yourself in drawRect, it sounds better performance wise (and of course because of your "ignoring bogus layer" message), to have some own values containing the scale and the offset, and respecting this in your drawing code. This way the layer's size will always stay the same and there is no need to draw that huge layer if most of it is outside of the displays bounds.

Of course it shouldn't be a child of the scrollView then, so you need to get the values from scrollViewDidScroll as well to calculate your currently visible rect.

Example of the idea:
if the current code in drawRect would look like

CGContextFillRect( CGRectMake(x,y,width,height) );

and you are scaling this by scaling the whole layer, I am suggesting to have a variable containing the current scale and don't scale the whole layer, like:

CGContextFillRect( CGRectMake(x* _zoomScale,y* _zoomScale,width* _zoomScale,height* _zoomScale) );

or even better use the scale and translate methods on the CGContext then your drawing code would be independent from these. The first three lines in drawRect should then be:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -_contentOffset.x, -_contentOffset.y);
CGContextScaleCTM(context, _zoomScale, _zoomScale);

make zoomScale and contentOffset a property and set it in the UIScrollViewDelegate methods.

Upvotes: 2

Mundi
Mundi

Reputation: 80271

Not sure if reading the transform.a is the right approach. Maybe better to use the scale variable from the method instead.

Upvotes: 0

Related Questions