Created
March 24, 2020 01:01
-
-
Save mmuszynski/42b0b2444a2cbcf3ff9307664de464c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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