2

I have a custom UIView that draws a check mark like so: (made in paintcode)

import UIKit

class AnimationCheckMarkView: UIView {

    override func draw(_ rect: CGRect) {

        //// General Declarations
        let context = UIGraphicsGetCurrentContext()

        //// Rectangle Drawing
        context!.saveGState()
        context!.translateBy(x: 62.33, y: 29.78)
        context!.rotate(by: 41.22 * CGFloat(M_PI) / 180)

        let rectanglePath = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 5, height: 28.79))
        UIColor.gray.setFill()
        rectanglePath.fill()

        context!.restoreGState()


        //// Rectangle 2 Drawing
        context!.saveGState()
        context!.translateBy(x: 49.07, y: 49.66)
        context!.rotate(by: 131.13 * CGFloat(M_PI) / 180)

        let rectangle2Path = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 5, height: 14.23))
        UIColor.gray.setFill()
        rectangle2Path.fill()

        context!.restoreGState()
    }

}

In my view controller I init the view like so:

checkMarkView = AnimationCheckMarkView()
checkMarkView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
addSubview(checkMarkView)

Later on I want to animate the size so I use:

UIView.animate(withDuration: 0.8, delay: 0.0, usingSpringWithDamping: 0.55, initialSpringVelocity: 0, options: [], animations: {
            self.checkMarkView.transform = CGAffineTransform(scaleX: 4, y: 4)
        }, completion: nil)

However it appears that the drawing becomes blurred when resized. What am I doing wrong here? Is there a better way to do this?

KexAri
  • 3,867
  • 6
  • 40
  • 80

0 Answers0