사용자의 서명을 받기 위한 Demo를 만드는 중...PencilKit에 대해 알게 된 것을 간단하게 정리해본다.
func newSignature() {
let newSignature = PKDrawing()
dataModel.signatures.append(newSignature)
...
}
@IBOutlet var canvasView: PKCanvasView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// set up the canvas view with the first drawing from the data model
canvasView.delegate = self
canvasView.drawing = dataModelController.signatures[signatureIndex]
canvasView.alwaysBounceVertical = true
}
https://developer.apple.com/documentation/pencilkit/pkdrawing
private func generateThumbnail(_ index: Int) {
let signature = signatures[index]
let aspectRatio = DataModelController.thumbnailSize.width / DataModelController.thumbnailSize.height
let thumbnailRect = CGRect(x: 0, y: 0, width: DataModel.canvasWidth, height: DataModel.canvasWidth / aspectRatio)
let thumbnailScale = UIScreen.main.scale * DataModelController.thumbnailSize.width / DataModel.canvasWidth
let traitCollection = thumbnailTraitCollection
thumbnailQueue.async {
traitCollection.performAsCurrent {
let image = signature.image(from: thumbnailRect, scale: thumbnailScale)
...
}
}
}
method를 살펴보자.
https://developer.apple.com/documentation/pencilkit/pkdrawing/3281893-image
func image(
from rect: CGRect,
scale: CGFloat
) -> UIImage
rect
scale