The app provides a simple drawing functionality on a canvas without using a storyboard. After creating drawings in portrait mode, rotating the simulator or the iPad-Device to landscape mode does not update or rescale the existing drawings to fit the newly expanded canvas area. The app can also be launched directly in landscape mode, allowing drawings to be created before rotating the device back to portrait mode. However, the issue persists, with the drawings not adjusting to the new canvas dimensions.
The goal is to achieve the same behavior as in the Apple Notes app: when the iPad is rotated, the drawings should adjust to the newly expanded or reduced canvas area. I would appreciate any suggestions or solutions.
Sample Projekt [https://github.com/GG88IOS/Test_Drawing_App)
I tested your code. When rotating, the canvas size changes, but the drawing remains the same.
I cannot find immediately in your code what should make the existing drawing scale to the new format. Where is it ?
Is it here ?
override func draw(_ rect: CGRect) {
super.draw(rect)
guard let context: CGContext = UIGraphicsGetCurrentContext() else { return }
for stroke in Database.strokes {
context.setLineCap(.round)
context.setLineJoin(.round)
context.setLineWidth(2.0)
context.setAlpha(1.0)
context.setBlendMode(.normal)
context.setStrokeColor(UIColor.black.cgColor)
context.addPath(stroke.path)
context.strokePath()
}
}
But Database.strokes is not scaled on device rotation. Why should the drawing change ?
Try to scale Database.strokes when you rotate device, then drawing will adapt.