6

I draw bezierpaths in a zoomable UIView (drawing layer of a pdf reader). When I zoom in the document the UIView zoom in too, but then all the drawings and lines looks much more pixelated. Is there a way to render those paths without too much pixelation? It supposed that bezier paths are vectorial based...

Thanks in advance!

Samui
  • 1,384
  • 3
  • 14
  • 28

2 Answers2

11

You are correct that a UIBezierPath is vector based. However, when you draw a path into a view, it uses the contentScale property on the views layer to determine the amount of detail to use when drawing.

What you could do is when the user finishes zooming, set the content scale to the correct amount.

drawingView.layer.contentScale = [[UIScreen mainScreen] scale] * zoomAmount;

Swift 5:

drawingView.layer.contentsScale = UIScreen.main.scale * zoomAmount
drawingView.setNeedsDisplay()

If you're using the view inside scrollview then call this in scrollViewDidEndZooming function to avoid unnecessary memory usage.

MysteryMoose
  • 2,211
  • 4
  • 23
  • 47
Craig Siemens
  • 12,942
  • 1
  • 34
  • 51
0

You can use CAShapeLayer instead. Just create CAShapeLayer, add CGPath and add a layer as sublayer to your UIView layer

Mark Pervovskiy
  • 1,123
  • 11
  • 18
  • Can you provide an example? I'm new at Quartz and drawing stuff. By now I'm drawing in drawRect method of my drawing UIView subclass using touchesbegan, moven and ended. - (void)drawRect:(CGRect)rect { [[UIColor redColor] setStroke]; for (UIBezierPath *path in self.pathArray) [path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0]; } – Samui Jul 23 '12 at 18:16
  • Something like that in your view initialization for (UIBezierPath *path in self.pathArray){ CAShapeLayer *layer1 = [CAShapeLayer layer]; layer1.strokeColor = [UIColor redColor].CGColor; layer1.path = path.CGPath; [self.layer addSublayer:layer1]; } – Mark Pervovskiy Jul 23 '12 at 18:30