Skip to content

Instantly share code, notes, and snippets.

@mmuszynski
Created March 24, 2020 01:01
Show Gist options
  • Save mmuszynski/42b0b2444a2cbcf3ff9307664de464c7 to your computer and use it in GitHub Desktop.
Save mmuszynski/42b0b2444a2cbcf3ff9307664de464c7 to your computer and use it in GitHub Desktop.
import UIKit
import PencilKit
class ViewController: UIViewController {
@IBOutlet var canvasView: PKCanvasView!
override func viewDidLoad() {
super.viewDidLoad()
//Set the canvas view to opaque and clear
canvasView.backgroundColor = UIColor(white: 0, alpha: 0.05)
canvasView.isOpaque = false
}
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
let targetTransform = coordinator.targetTransform
self.canvasView.drawing.transform(using: targetTransform)
}
var oldCanvasSize: CGSize!
var newCanvasSize: CGSize!
override func viewWillLayoutSubviews() {
oldCanvasSize = canvasView.bounds.size
}
override func viewDidLayoutSubviews() {
newCanvasSize = canvasView.bounds.size
let targetTransform = CGAffineTransform(scaleX: newCanvasSize.width / oldCanvasSize.width, y: newCanvasSize.height / oldCanvasSize.height)
self.canvasView.drawing.transform(using: targetTransform)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment