1

How can a UITextView be scaled (by UIPinchGestureRecognizer) without losing text clarity?

This is the blurry UITextView when scaled up:

enter image description here

This is the desired effect (created on Snapchat).

enter image description here

Here is my code:

func scale(_ sender:UIPinchGestureRecognizer) {
    sender.view?.transform = (sender.view?.transform.scaledBy(x: sender.scale, y: sender.scale))!
    sender.scale = 1
}
Peter Tao
  • 1,668
  • 6
  • 18
  • 29

1 Answers1

2

You need to change the UIFont size when you scale up your UITextView.

Otherwise your text will get blurry because you are scaling up the actual frame of the UITextView together with the text but the current UIFont is still a small size so you will see it as pixelated and blurry.

EDIT: Calculate font size:

Resize font size to fill UITextView?

Community
  • 1
  • 1
  • Thanks Sneak for getting back so quickly. What is the best way of changing the UIFont size in proportion to the scale? – Peter Tao Feb 25 '17 at 03:23
  • @PeterTao You should first of all only change the font when the **gesture.state has ended**, to avoid performance issues. Second, I have never done it but basically you should calculate the textView.bounds.size.height (if it's single line text) and set an equivalant size to the font or something. The best way is if you just try and see what size works and is visually sharp without getting pixelated. –  Feb 25 '17 at 03:27
  • Not working for me. Is there anything do i need to taking care for? – PinkeshGjr Jan 12 '19 at 11:30