PencilKit

RSS for tag

Capture touch input as an opaque drawing and turn it into high-quality images that can be displayed on iOS and macOS using PencilKit.

Posts under PencilKit tag

134 Posts

Post

Replies

Boosts

Views

Activity

PKCanvasView size error
Here is the implementation. import SwiftUI import PencilKit struct DrawingCanvas_bug: UIViewRepresentable { typealias UIViewType = PKCanvasView private let toolPicker = PKToolPicker() @Binding var drawing: PKDrawing var isOpaque: Bool = true var drawingDidChange: ((PKDrawing) -> Void)? func makeUIView(context: Context) -> PKCanvasView { let canvasView = PKCanvasView(frame: .zero) canvasView.drawing = drawing canvasView.delegate = context.coordinator canvasView.backgroundColor = .clear canvasView.isOpaque = isOpaque canvasView.alwaysBounceVertical = true // The size of the canvas is Zero, so I cannot update the ZoomScale now. // context.coordinator.updateZoomScale(for: canvasView) toolPicker.setVisible(true, forFirstResponder: canvasView) toolPicker.addObserver(canvasView) canvasView.becomeFirstResponder() return canvasView } func updateUIView(_ canvasView: PKCanvasView, context: Context) { DispatchQueue.main.async { // We can get the correct ZoomScale and the correct ContentSize, but part of the drawing is not visible. // Using the select tool can select them. context.coordinator.updateZoomScale(for: canvasView) } } func makeCoordinator() -> Coordinator { Coordinator(self) } static func dismantleUIView(_ canvasView: PKCanvasView, coordinator: Coordinator) { canvasView.resignFirstResponder() } } extension DrawingCanvas_bug { class Coordinator: NSObject, PKCanvasViewDelegate { var host: DrawingCanvas_bug init(_ host: DrawingCanvas_bug) { self.host = host } func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) { host.drawing = canvasView.drawing if let action = host.drawingDidChange { action(canvasView.drawing) } updateContentSizeForDrawing(for: canvasView) } func updateZoomScale(for canvasView: PKCanvasView) { let canvasScale = canvasView.bounds.width / 768 canvasView.minimumZoomScale = canvasScale canvasView.maximumZoomScale = canvasScale canvasView.zoomScale = canvasScale updateContentSizeForDrawing(for: canvasView) } func updateContentSizeForDrawing(for canvasView: PKCanvasView) { let drawing = canvasView.drawing let contentHeight: CGFloat if !drawing.bounds.isNull { contentHeight = max(canvasView.bounds.height, (drawing.bounds.maxY + 500) * canvasView.zoomScale) } else { contentHeight = canvasView.bounds.height } canvasView.contentSize = CGSize(width: 768 * canvasView.zoomScale, height: contentHeight) } } } And here is how I use: NavigationSplitView(columnVisibility: .constant(.doubleColumn)) {     List(selection: $selection) {         ForEach(drawingModel.drawings, id: \.uuidString) {             DrawingRow(drawingData: $0)         }     } } detail: {     DrawingView() } .navigationSplitViewStyle(.balanced) // <- If I use automatic style, PKCanvasView's size is correct
1
0
1.8k
Aug ’22
Very high CPU usage when draw a stroke on a canvas with more than 5000 strokes
Many users reported my app use too much energy. I have profiled the app and find out the problem is from PencilKit. It only happens on a canvas with more than 5000 strokes: When user use pen or any ink tool to draw something on the screen and leave the pencil off from the screen, the CPU go immediately to 100-165% for 3 seconds then go back to 0%. I have time profiled CPU and found out that 90% of the calculation are from CoreHandwriting. I suppose each time when user did draw something on the screen, PencilKit will try to recognize text from the handwriting in the background. That leads to high CPU usage. If this is true, I hope there will be an option to disable the CoreHandwriting. Otherwise I hope PencilKit will be updated to consume less energy, because my app received many bad reviews because of this problem and I can't do anything.
1
0
1.8k
Aug ’22
A serious bug in PencilKit that make all apps with PencilKit useless in iOS16
After testing iOS16, I've found a serious bug that make all apps with PencilKit (Prodrafts, InDraft, Pencil it in, Paint...) completely useless: If a canvasView is scrolled, all existing strokes will be shifted while writing with Apple Pencil. After writing, all strokes will be shifted back to its positions but it make users unable to write anything. This bug is also occurs in the example app of PencilKit: https://developer.apple.com/documentation/pencilkit/drawing_with_pencilkit It's easy to reprocedure: Run the example app, open a note, scroll down, then write something. You will see the bug (this bug only happens in iOS 16 and iPadOS 16). I have sent multiple bug reports since the first days of the beta, none of them are answered. It's been 2 beta versions and the bug has not been fixed yet. I'm an indie developer and I have worked with my app for 2 years - full time - 12 hours a day - no weekend. The main feature of my app is taking note with Apple Pencil and this bug made my app completely broken. I'm terrifying that 2 years of my work will be wasted. Please answer me, give me hope. Thank you :(
2
2
2.3k
Jul ’22
PencilKit is throwing GPU/Metal errors (Insufficient Memory)
For context: I'm working on a score pad app, with the ability to have a column of PKCanvases, so you can just hand write things without them being scribbled into text. As part of my stress testing, I basically filled the grid with ~50 canvases, and it seems that after a certain amount of CanvasViews are added to the score pad, my M1 iPad Pro GPU is unable to keep up. Occasionally, a cell will just entirely render as magenta, and I will have dozens and dozens of Execution of the command buffer was aborted due to an error during execution. Insufficient Memory (IOAF code 8) logs thrown to the console. I honestly don't know where to go from here. I recognize that what I'm doing is almost definitely not what PencilKit was designed for, but I also know the API is relatively young. I can't tell if this is a bug that should be fixed by Apple, or entirely my fault and a sign that I need to redo the entire thing. I've attached a screenshot with the magenta cell, there's also another two cells where the pencil strokes are just thick black squares. I'd appreciate any advice or help, I can't even seem to find any way to detect and recover from this in my code, as trying to search for Metal errors gives me discussions about writing Metal apps, which this isn't. It's a pure SwiftUI app with some PencilKit canvases.
6
0
3.9k
Jul ’22
PencilKit ColorPicker in ToolPicker color mode mismatch
I'm currently using PencilKit in an app that is forced to run in dark mode (UIUserInterfaceStyle == Dark in Info.plist). But for one UIViewController only, I'm using the light mode for note taking with PencilKit. I change the ToolPicker style by using toolPicker.overrideUserInterfaceStyle = .light and it works great that way. Unfortunately, if I want a custom color and I tap on the ColorPicker icon, it seems to still be in dark mode, because when I choose white, it draws black, and if I choose black, it draws black. This doesn't happen if I tap the black color in the predefined palette (not the color picker). Any idea how to force to color picker to respect the tool picker userInterfaceStyle?
2
2
2.4k
Jun ’22
How to build a flood fill tool in PencilKit?
I want to create a flood fill (aka paint bucket) tool with PencilKit. I am aware of the way to inspect the PKStrokes to identify an enclosed space to fill inside of them but I'm not sure the way to create the internal shape inside that space. Any suggestion or leads would be appreciated. Thanks in advance and please have a beautiful day.
1
0
1.5k
May ’22
High CPU usage (167%) just by scrolling canvasView in the sample project
In the sample project "Drawing with PencilKit", even scrolling by 1 pixel can cause my iPad Pro to use 167% CPU and keep this usage for 2-5 seconds. My iPad got too hot after few minutes that I can't barely put my palm on it. This a serious problem and could be reprocedure easily: Run the sample "Drawing with PencilKit" on your iPad Open the sample note Select all strokes in the note and duplicate about 7 times (it is just an average number of strokes I write in a page on a note-taking app like GoodNotes). Scroll and watch the CPU usage jumps in Xcode It is not matter how long you scroll or how many strokes are visible on the screen. If the drawing has that much strokes, the CoreHandwriting objects will eat all the CPU. I hope it got fixed soon because it make apps with PencilKit consume too much baterry, getting too hot and we receive many bad review because of it :( Many thank to Pencil and Paperteam for developing this Framework btw, this framework is awesome, but it could be better, I believe.
0
0
1.4k
May ’22
Is it a bug of PencilKit?
When I use pencil or highlighter of PencilKit on debug, and write it quickly, it'll crash. But it's fine on release the error message: -[MTLDebugCommandBuffer lockPurgeableObjects]:2103: failed assertion `MTLResource 0x2816cd0a0 (label: (null)), referenced in cmd buffer 0x11a041400 (label: Live rendering command buffer) is in volatile or empty purgeable state at commit' is it a bug, or am I making something wrong?
1
0
1.3k
Apr ’22
PencilKit clearing canvas not always working
I am building a PencilKit app that interprets a canvasView.drawing's size. Drawings below a certain size are interpreted as tap gestures and get cleared in the interpretation process. Effectively, I am doing it like this: func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) { // Check if drawing is empty, // otherwise this would loop guard !canvasView.drawing.bounds.isEmpty else { return } if canvasView.drawing.bounds.width 10 &amp;&amp; canvasView.drawing.bounds.height 10 { canvasView.drawing = PKDrawing() handleDetectedTapGesture() } } On my 2020 iPad Pro, this works flawlessly. On other iPads however, I observe a strange behaviour: In a series of drawing little specks on the canvas that are all supposed to be cleared immediately, sometimes the canvas seems to not be cleared, a single speck stays visible. After I draw the next speck somewhere else, the clearing is functional again, which means the canvas was internally emptied, the visible state was just not up-to-date. Finger input on the canvas is deactivated. The canvas tool is set to pencil, width 5.0. Does anybody have an idea what could be the reason for this behaviour?
1
0
1.7k
Mar ’22
PKCanvasView acting weird after it's resized
Every time I resize the PKCanvasView on a button tap, PKCanvasView, sometimes a few strokes later, sometimes on the first stroke after resize, removes all strokes except the one currently being drawn & this happens as soon as I start to draw. Then, when I lift the pencil up & away from screen, all previous strokes become visible except the one I just drew. And then, on the very next stroke, the drawing is updated correctly, with all strokes correctly visible. This is how I update the view when it's resized: UIView.animate(withDuration: 0.3, animations: { self.descriptionPane.isHidden = self.canvasToggle.isSelected (self.descriptionPane.superview as! UIStackView).layoutIfNeeded() self.currentMaxZoomScale = self.canvasToggle.isSelected ? (self.canvasView.bounds.width / oldCanvasRect.width) : 1 self.canvasView.maximumZoomScale = self.currentMaxZoomScale self.canvasView.setZoomScale(self.currentMaxZoomScale, animated: false) self.canvasView.setContentOffset(CGPoint(x: 0,y: 0), animated: false) }, completion: { isComplete in self.canvasToggle.isUserInteractionEnabled = true self.canvasView.isUserInteractionEnabled = true }) I more often than not see the following warning when I this problem occurs. [Stroke Generator] Missed updates at end of stroke: 2 (total points: 69) Could anyone guide me on how I should approach this problem? Is it even a good idea to resize the canvas?
0
0
964
Mar ’22
PencilKit crashing on iOS 15.1 on iPad
I am starting to work with PencilKit and have a small sample app set up with Swift. When I draw a line too long it will crash from com.apple.pencilkit.renderer with the following: -[MTLDebugCommandBuffer lockPurgeableObjects]:2103: failed assertion `MTLResource 0x280584a10 (label: (null)), referenced in cmd buffer 0x107019400 (label: Live rendering command buffer) is in volatile or empty purgeable state at commit' I can draw lots of small lines without issue. Doesn't seem to matter what size the canvas is or any other specific attributes I can determine. It's a quick sample so there's really not much going on, and this appears to be coming from pencil kit and metal under the hood. I am using an iPad pro, iOS 15.1 and a pencil2 and using finger to draw with the same crash if it helps.
4
0
2.2k
Mar ’22
Using PencilKit with PDFKit
I'm developing an app that allows you to view PDFs (music notes). I'm using PDFkit to display the pdf and need the pencilkit functionality while viewing the pdf (in the same way that you could mark up a book you are reading in iBooks when you click on the "Mark up" button). I am able to add a canvas on top of the pdf view however, I cannot save the canvas to be merged with the PDF. QuickLook offers a solution because the pencilkit looks to be built into it and works perfectly just the way I need it to, however, I don't need the other things that come with QuickLook. I desperately need your help with how I can get the pencilkit functionality on my custom PDF viewing app. At this point, I can't even find a solution for the "Mark up" button (pencil.tip.crop.circle) to be filled when tapped. Thank you in advance!
2
0
2.3k
Jan ’22
PKCanvasView size error
Here is the implementation. import SwiftUI import PencilKit struct DrawingCanvas_bug: UIViewRepresentable { typealias UIViewType = PKCanvasView private let toolPicker = PKToolPicker() @Binding var drawing: PKDrawing var isOpaque: Bool = true var drawingDidChange: ((PKDrawing) -> Void)? func makeUIView(context: Context) -> PKCanvasView { let canvasView = PKCanvasView(frame: .zero) canvasView.drawing = drawing canvasView.delegate = context.coordinator canvasView.backgroundColor = .clear canvasView.isOpaque = isOpaque canvasView.alwaysBounceVertical = true // The size of the canvas is Zero, so I cannot update the ZoomScale now. // context.coordinator.updateZoomScale(for: canvasView) toolPicker.setVisible(true, forFirstResponder: canvasView) toolPicker.addObserver(canvasView) canvasView.becomeFirstResponder() return canvasView } func updateUIView(_ canvasView: PKCanvasView, context: Context) { DispatchQueue.main.async { // We can get the correct ZoomScale and the correct ContentSize, but part of the drawing is not visible. // Using the select tool can select them. context.coordinator.updateZoomScale(for: canvasView) } } func makeCoordinator() -> Coordinator { Coordinator(self) } static func dismantleUIView(_ canvasView: PKCanvasView, coordinator: Coordinator) { canvasView.resignFirstResponder() } } extension DrawingCanvas_bug { class Coordinator: NSObject, PKCanvasViewDelegate { var host: DrawingCanvas_bug init(_ host: DrawingCanvas_bug) { self.host = host } func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) { host.drawing = canvasView.drawing if let action = host.drawingDidChange { action(canvasView.drawing) } updateContentSizeForDrawing(for: canvasView) } func updateZoomScale(for canvasView: PKCanvasView) { let canvasScale = canvasView.bounds.width / 768 canvasView.minimumZoomScale = canvasScale canvasView.maximumZoomScale = canvasScale canvasView.zoomScale = canvasScale updateContentSizeForDrawing(for: canvasView) } func updateContentSizeForDrawing(for canvasView: PKCanvasView) { let drawing = canvasView.drawing let contentHeight: CGFloat if !drawing.bounds.isNull { contentHeight = max(canvasView.bounds.height, (drawing.bounds.maxY + 500) * canvasView.zoomScale) } else { contentHeight = canvasView.bounds.height } canvasView.contentSize = CGSize(width: 768 * canvasView.zoomScale, height: contentHeight) } } } And here is how I use: NavigationSplitView(columnVisibility: .constant(.doubleColumn)) {     List(selection: $selection) {         ForEach(drawingModel.drawings, id: \.uuidString) {             DrawingRow(drawingData: $0)         }     } } detail: {     DrawingView() } .navigationSplitViewStyle(.balanced) // <- If I use automatic style, PKCanvasView's size is correct
Replies
1
Boosts
0
Views
1.8k
Activity
Aug ’22
Very high CPU usage when draw a stroke on a canvas with more than 5000 strokes
Many users reported my app use too much energy. I have profiled the app and find out the problem is from PencilKit. It only happens on a canvas with more than 5000 strokes: When user use pen or any ink tool to draw something on the screen and leave the pencil off from the screen, the CPU go immediately to 100-165% for 3 seconds then go back to 0%. I have time profiled CPU and found out that 90% of the calculation are from CoreHandwriting. I suppose each time when user did draw something on the screen, PencilKit will try to recognize text from the handwriting in the background. That leads to high CPU usage. If this is true, I hope there will be an option to disable the CoreHandwriting. Otherwise I hope PencilKit will be updated to consume less energy, because my app received many bad reviews because of this problem and I can't do anything.
Replies
1
Boosts
0
Views
1.8k
Activity
Aug ’22
A serious bug in PencilKit that make all apps with PencilKit useless in iOS16
After testing iOS16, I've found a serious bug that make all apps with PencilKit (Prodrafts, InDraft, Pencil it in, Paint...) completely useless: If a canvasView is scrolled, all existing strokes will be shifted while writing with Apple Pencil. After writing, all strokes will be shifted back to its positions but it make users unable to write anything. This bug is also occurs in the example app of PencilKit: https://developer.apple.com/documentation/pencilkit/drawing_with_pencilkit It's easy to reprocedure: Run the example app, open a note, scroll down, then write something. You will see the bug (this bug only happens in iOS 16 and iPadOS 16). I have sent multiple bug reports since the first days of the beta, none of them are answered. It's been 2 beta versions and the bug has not been fixed yet. I'm an indie developer and I have worked with my app for 2 years - full time - 12 hours a day - no weekend. The main feature of my app is taking note with Apple Pencil and this bug made my app completely broken. I'm terrifying that 2 years of my work will be wasted. Please answer me, give me hope. Thank you :(
Replies
2
Boosts
2
Views
2.3k
Activity
Jul ’22
PencilKit is throwing GPU/Metal errors (Insufficient Memory)
For context: I'm working on a score pad app, with the ability to have a column of PKCanvases, so you can just hand write things without them being scribbled into text. As part of my stress testing, I basically filled the grid with ~50 canvases, and it seems that after a certain amount of CanvasViews are added to the score pad, my M1 iPad Pro GPU is unable to keep up. Occasionally, a cell will just entirely render as magenta, and I will have dozens and dozens of Execution of the command buffer was aborted due to an error during execution. Insufficient Memory (IOAF code 8) logs thrown to the console. I honestly don't know where to go from here. I recognize that what I'm doing is almost definitely not what PencilKit was designed for, but I also know the API is relatively young. I can't tell if this is a bug that should be fixed by Apple, or entirely my fault and a sign that I need to redo the entire thing. I've attached a screenshot with the magenta cell, there's also another two cells where the pencil strokes are just thick black squares. I'd appreciate any advice or help, I can't even seem to find any way to detect and recover from this in my code, as trying to search for Metal errors gives me discussions about writing Metal apps, which this isn't. It's a pure SwiftUI app with some PencilKit canvases.
Replies
6
Boosts
0
Views
3.9k
Activity
Jul ’22
Apple pen and gaming
Years ago I used to use the Apple Pencil to play pubg. I used to move with my left hand and use the pencil in my right to control the view and shoot. I played today for the first time in a while and the pencil no longer works if my hand is already using the left side. Please tell me there’s a fix for this!!
Replies
0
Boosts
0
Views
1.3k
Activity
Jun ’22
PencilKit lasso tool does not focus on the pasted stroke
I am trying to use the PencilKit to build a note App. One of the issue I had was that if I use the lasso tool to select and copy a stroke, and pasted the stroke that I copied, the lasso tool focuses on the original stroke instead of the newly pasted one. Wondering if anyone have the same issue, and how can I solve it? I uploaded a demo git in stack overflow
Replies
0
Boosts
0
Views
660
Activity
Jun ’22
PencilKit ColorPicker in ToolPicker color mode mismatch
I'm currently using PencilKit in an app that is forced to run in dark mode (UIUserInterfaceStyle == Dark in Info.plist). But for one UIViewController only, I'm using the light mode for note taking with PencilKit. I change the ToolPicker style by using toolPicker.overrideUserInterfaceStyle = .light and it works great that way. Unfortunately, if I want a custom color and I tap on the ColorPicker icon, it seems to still be in dark mode, because when I choose white, it draws black, and if I choose black, it draws black. This doesn't happen if I tap the black color in the predefined palette (not the color picker). Any idea how to force to color picker to respect the tool picker userInterfaceStyle?
Replies
2
Boosts
2
Views
2.4k
Activity
Jun ’22
How to build a flood fill tool in PencilKit?
I want to create a flood fill (aka paint bucket) tool with PencilKit. I am aware of the way to inspect the PKStrokes to identify an enclosed space to fill inside of them but I'm not sure the way to create the internal shape inside that space. Any suggestion or leads would be appreciated. Thanks in advance and please have a beautiful day.
Replies
1
Boosts
0
Views
1.5k
Activity
May ’22
Apple pencil battery jumped from 34% to 100%
I connected my pencil to charge but the number didn’t change even after a while. I forget/reconnect it, and the battery was full (it was 34% before). Why did that happen?
Replies
1
Boosts
0
Views
736
Activity
May ’22
Apple pencil 2 Scribble in the latest IpadOS 15.5
Hi everyone, i have two questions about pencil 2 that how many language does it support using scribble? At the present, i know it supports english and japanese. The second quesion is... How long can its battery use in once full charge? Thanks
Replies
1
Boosts
0
Views
1.7k
Activity
May ’22
High CPU usage (167%) just by scrolling canvasView in the sample project
In the sample project "Drawing with PencilKit", even scrolling by 1 pixel can cause my iPad Pro to use 167% CPU and keep this usage for 2-5 seconds. My iPad got too hot after few minutes that I can't barely put my palm on it. This a serious problem and could be reprocedure easily: Run the sample "Drawing with PencilKit" on your iPad Open the sample note Select all strokes in the note and duplicate about 7 times (it is just an average number of strokes I write in a page on a note-taking app like GoodNotes). Scroll and watch the CPU usage jumps in Xcode It is not matter how long you scroll or how many strokes are visible on the screen. If the drawing has that much strokes, the CoreHandwriting objects will eat all the CPU. I hope it got fixed soon because it make apps with PencilKit consume too much baterry, getting too hot and we receive many bad review because of it :( Many thank to Pencil and Paperteam for developing this Framework btw, this framework is awesome, but it could be better, I believe.
Replies
0
Boosts
0
Views
1.4k
Activity
May ’22
any updates about Snap to Shape feature's public availability ?
i read year old post here https://developer.apple.com/forums/thread/650386?answerId=628394022#reply-to-this-question , where it is said it's not available for everyone right now. does anyone have any info about this when snap to Shape and writing to text might be available for every one ?
Replies
0
Boosts
0
Views
884
Activity
May ’22
iPad OS 15.5 beta 3/Apple Pencil/Magic Keyboard issue
Seeing an issue with 15.5 beta 3, where the Apple Pencil disconnects from the iPad Pro 3rd gen when the iPad is also connected to the Magic Keyboard. Once I disconnect the keyboard the Apple Pencil works again. Anyone else seeing this?
Replies
2
Boosts
0
Views
1.4k
Activity
May ’22
Is it a bug of PencilKit?
When I use pencil or highlighter of PencilKit on debug, and write it quickly, it'll crash. But it's fine on release the error message: -[MTLDebugCommandBuffer lockPurgeableObjects]:2103: failed assertion `MTLResource 0x2816cd0a0 (label: (null)), referenced in cmd buffer 0x11a041400 (label: Live rendering command buffer) is in volatile or empty purgeable state at commit' is it a bug, or am I making something wrong?
Replies
1
Boosts
0
Views
1.3k
Activity
Apr ’22
PencilKit clearing canvas not always working
I am building a PencilKit app that interprets a canvasView.drawing's size. Drawings below a certain size are interpreted as tap gestures and get cleared in the interpretation process. Effectively, I am doing it like this: func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) { // Check if drawing is empty, // otherwise this would loop guard !canvasView.drawing.bounds.isEmpty else { return } if canvasView.drawing.bounds.width 10 &amp;&amp; canvasView.drawing.bounds.height 10 { canvasView.drawing = PKDrawing() handleDetectedTapGesture() } } On my 2020 iPad Pro, this works flawlessly. On other iPads however, I observe a strange behaviour: In a series of drawing little specks on the canvas that are all supposed to be cleared immediately, sometimes the canvas seems to not be cleared, a single speck stays visible. After I draw the next speck somewhere else, the clearing is functional again, which means the canvas was internally emptied, the visible state was just not up-to-date. Finger input on the canvas is deactivated. The canvas tool is set to pencil, width 5.0. Does anybody have an idea what could be the reason for this behaviour?
Replies
1
Boosts
0
Views
1.7k
Activity
Mar ’22
PKCanvasView acting weird after it's resized
Every time I resize the PKCanvasView on a button tap, PKCanvasView, sometimes a few strokes later, sometimes on the first stroke after resize, removes all strokes except the one currently being drawn & this happens as soon as I start to draw. Then, when I lift the pencil up & away from screen, all previous strokes become visible except the one I just drew. And then, on the very next stroke, the drawing is updated correctly, with all strokes correctly visible. This is how I update the view when it's resized: UIView.animate(withDuration: 0.3, animations: { self.descriptionPane.isHidden = self.canvasToggle.isSelected (self.descriptionPane.superview as! UIStackView).layoutIfNeeded() self.currentMaxZoomScale = self.canvasToggle.isSelected ? (self.canvasView.bounds.width / oldCanvasRect.width) : 1 self.canvasView.maximumZoomScale = self.currentMaxZoomScale self.canvasView.setZoomScale(self.currentMaxZoomScale, animated: false) self.canvasView.setContentOffset(CGPoint(x: 0,y: 0), animated: false) }, completion: { isComplete in self.canvasToggle.isUserInteractionEnabled = true self.canvasView.isUserInteractionEnabled = true }) I more often than not see the following warning when I this problem occurs. [Stroke Generator] Missed updates at end of stroke: 2 (total points: 69) Could anyone guide me on how I should approach this problem? Is it even a good idea to resize the canvas?
Replies
0
Boosts
0
Views
964
Activity
Mar ’22
PencilKit crashing on iOS 15.1 on iPad
I am starting to work with PencilKit and have a small sample app set up with Swift. When I draw a line too long it will crash from com.apple.pencilkit.renderer with the following: -[MTLDebugCommandBuffer lockPurgeableObjects]:2103: failed assertion `MTLResource 0x280584a10 (label: (null)), referenced in cmd buffer 0x107019400 (label: Live rendering command buffer) is in volatile or empty purgeable state at commit' I can draw lots of small lines without issue. Doesn't seem to matter what size the canvas is or any other specific attributes I can determine. It's a quick sample so there's really not much going on, and this appears to be coming from pencil kit and metal under the hood. I am using an iPad pro, iOS 15.1 and a pencil2 and using finger to draw with the same crash if it helps.
Replies
4
Boosts
0
Views
2.2k
Activity
Mar ’22
PKCanvasView and document based App
I created a document based app with SwiftUI and a PKCanvasView. Now I want to save the drawings of the PKCanvasView inside of the file. How can I do this?
Replies
0
Boosts
0
Views
1.3k
Activity
Jan ’22
How to use 'dataRepresentation()' with PKCanvasView in Swift?
The title is my question.
Replies
0
Boosts
0
Views
930
Activity
Jan ’22
Using PencilKit with PDFKit
I'm developing an app that allows you to view PDFs (music notes). I'm using PDFkit to display the pdf and need the pencilkit functionality while viewing the pdf (in the same way that you could mark up a book you are reading in iBooks when you click on the "Mark up" button). I am able to add a canvas on top of the pdf view however, I cannot save the canvas to be merged with the PDF. QuickLook offers a solution because the pencilkit looks to be built into it and works perfectly just the way I need it to, however, I don't need the other things that come with QuickLook. I desperately need your help with how I can get the pencilkit functionality on my custom PDF viewing app. At this point, I can't even find a solution for the "Mark up" button (pencil.tip.crop.circle) to be filled when tapped. Thank you in advance!
Replies
2
Boosts
0
Views
2.3k
Activity
Jan ’22