Hey Guys,
Finally, I was able to fix the font blurring issue successfully.
We have to consider scale factor both UITextView and CALayer of the UIView.
We need to update scale factor subviews as well using recursion.
func scaleView( view: UIView, scale: CGFloat ){
view.contentScaleFactor = scale
for vi in view.subviews {
scaleView(view: vi, scale: scale)
}
}
func scaleLayer( layer: CALayer, scale: CGFloat ){
layer.contentsScale = scale
if layer.sublayers == nil {
return
}
for la in layer.sublayers! {
scaleLayer(layer: la, scale: scale)
}
}
We should call the above two methods for UITextView in scrollViewDidEndZooming (which is inherited from UIScrollViewDelegate) method.
func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
scaleView(view: textView, scale: scale)
scaleLayer(layer: textView.layer, scale: scale)
}
But for the zoom-out feature, please don't set scale value directly then quality will lose. So need to keep the threshold value,it should be calculated according to your usage.
Topic:
Programming Languages
SubTopic:
Swift
Tags: