我有一个自定义UIView,它绘制一个复选标记,如下所示:(在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()
}
}
在我的视图控制器中,我这样初始化视图:
checkMarkView = AnimationCheckMarkView()
checkMarkView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
addSubview(checkMarkView)
稍后我想要设置大小的动画,所以我使用:
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)
然而,调整大小时图形似乎变得模糊。我在这做错了什么?有更好的方法吗?