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

PencilKit new tools only available for some developers
Hello, I was trying to use the new Pencilkit tools watercolor, monoline fountainpen but there is no way to implement them in Xcode. There is even a Link to Apples documentation but it's not accessible in Xcode somehow. https://developer.apple.com/documentation/pencilkit/pkinkingtool/inktype/monoline?language=o_9 First I thought they did the same thing like back in the days where they added the shape recognition feature and then removed it after a few weeks. !!But it looks like as if some apps have access to this new tools for example PRODRAFTS ... How is that possible ?? !!
1
2
1.4k
Jan ’23
pencil kit issue--drawing can't stay on canvas
I want to use pencil kit in my swiftui app. I encapsulate PKCanvasView in UIViewRepresentable. I can draw on canvas with only one stroke. However, the image will disappear immediately when I release the finger. Am I missing anything? import SwiftUI import PencilKit struct ContentView: View { var body: some View { CanvasView() } } struct CanvasView: UIViewRepresentable { func makeUIView(context: Context) -> PKCanvasView { let canvas = PKCanvasView() canvas.tool = PKInkingTool(.pen, color: .green, width: 10) canvas.drawingPolicy = .anyInput return canvas } func updateUIView(_ uiView: PKCanvasView, context: Context) { } }
1
1
1.4k
Dec ’22
PencilKit '.monoline' as a PKInkingTool.InkType suddenly doesn't work anymore
Hello Guys, I am writing a program using PencilKit. Yesterday, everything worked fine with this line: @State var pencilStyle: PKInkingTool.InkType = .monoline But today, i am getting this Error: Type 'PKInkingTool.InkType' has no member 'monoline'" When I started Xcode Today, it downloaded a new Simulator for iOS 16.2. How can I fix this issue? I can't use my Projekt without fixing this... Thanks in advance <3
0
1
1k
Dec ’22
Why doesn't PKStroke conform to Hashable?
I want to work directly with PKStrokes in my app. To transform and change them individually. By one or by grouping them. I thought a perfect way of keeping track of them is to put them in a Set<PKStroke>. By doing this I receive an error: "Type 'PKStroke' does not conform to protocol 'Hashable'". Correct me if I'm wrong, but aren't all PKStrokes unique? Thus they should be eligible to be kept in a Set? What is a correct way of accessing/grouping/storing PKStrokes then? Manually searching for them in canvasView.drawing.strokes? Thank you very much!
0
1
976
Dec ’22
PencilKit SwiftUI issue (disappearing strokes) on iOS 16 Simulator
We are using a SwiftUI view backed by PencilKit and are experiencing an issue on iOS 16 where drawn strokes disappear from the drawing (the drawing is empty after the stroke ends). Debugging the issue shows that PKCanvasView's drawing collection of strokes is increasing, yet they are not being rendered. Details: I'm on macOS 12.6 Monterey The bug surfaces in Xcode 14.1 / iOS 16.1 (I didn't check the Xcode 14.0 / 14.0.1). The code works as expected in Xcode 13.4.1 / iOS 15.5. The bug appears not to happen on device (iPhone 13 Pro / iOS 16.1.1) Example code demonstrating the issue: I have added a couple of print statements to show what is happening and to count the brush strokes of the PKDrawing. Please see the attached GIFs below that demonstrate the issue. import SwiftUI import PencilKit public struct TestCanvas {     private static let defaultTool = PKInkingTool(.pen, color: .darkGray, width: 5) } // MARK: UIViewRepresentable extension TestCanvas: UIViewRepresentable {     public func makeUIView(context: Context) -> some UIView {         print("make ui view")         let canvasView = PKCanvasView()         canvasView.delegate = context.coordinator         canvasView.drawingPolicy = .anyInput         canvasView.tool = Self.defaultTool         canvasView.isRulerActive = false         canvasView.backgroundColor = .clear         canvasView.isOpaque = true         return canvasView     }     public func updateUIView(_ uiView: UIViewType, context: Context) {         print("update ui view")     }     public func makeCoordinator() -> Coordinator {         Coordinator(self)     } } // MARK: Coordinator public extension TestCanvas {     @MainActor final class Coordinator: NSObject {         private let parent: TestCanvas         init(_ parent: TestCanvas) {             print("init coordinator")             self.parent = parent             super.init()         }     } } // MARK: PKCanvasViewDelegate extension TestCanvas.Coordinator: PKCanvasViewDelegate {     public func canvasViewDidEndUsingTool(_ canvasView: PKCanvasView) {         print("canvas did end using tool (\(canvasView.drawing.strokes.count) strokes)")     }     public func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) {         print("drawing did change (\(canvasView.drawing.strokes.count) strokes)")     } } Xcode 14.1 / iOS 16.1 PencilKit issue occurs on Xcode 14.1 / iOS 16.1 Simulator. Note the strokes disappear, yet the drawing's strokes keep incrementing. Xcode 13.4.1 / iOS 15.5 It works fine in Xcode 13.4.1 / iOS 15.5 Simulator. iPhone 13 Pro / iOS 16.1.1 I don't experience the issue on device (iPhone 13 Pro, iOS 16.1.1).
3
1
2.8k
Nov ’22
PKCanvasView broken on iOS 16?
I have a PKCanvasView in my app where the user can draw, very simple, no use of pencils or toolpickers, just a straight up signature drawing. For some reason, on iOS 16, the canvas seems to be broken, meaning the drawing disappears as soon as the user lifts their finger. The canvas still holds the drawing in its memory, as evidenced by the drawings raw size increasing with every finger stroke, but the drawing is never actually shown. It seems a lot of people using PKCanvasView are complaining about this all over the internet right now, does anyone have a workaround? Is there a way to make Apple aware of this?
0
2
1k
Nov ’22
Unable to set PKInk color to black
For some reasons I am unable to set PKInk color to black. It works with yellow, red, blue, …but black is just ignored and I get the stroke in white. This is really weird and I don’t know why. I tried by setting black to PKInkingTool and even by creating a stroke manually and set the PKInk color to black. Do you have an idea? Thanks.
1
0
1.8k
Oct ’22
Color intensity increases when converting PKDrawing data to uiimage
I am trying to convert PKDrawing data to uiimage. Thus I've used apple's API PKDrawing data to uiimage. But the colour intensity of the converted image increases surprisingly. I mean there is a difference between the canvas data and the converted uiimage. What could be the reason behind that? Here is the scenario Preview Drawing Data on CanvasView Preview after converting Drawing Data to uiimage
1
0
1.1k
Oct ’22
Random crashing issue with PencilKit
Hi, in my app I don't use PencilKit anywhere, yet I keep getting the following crash: Pencil Kit Crash.txt I don't even know where to start in debugging this. Could this be a bug within UIKit? It obviously only occurs in iPad devices and so far not in iOS16, but that may just be because of sample size. Do I need to handle touches differently for when a user uses an Apple Pen? Any help is appreciated. Thanks.
1
0
1.2k
Oct ’22
Shape detection for other apps? (PencilKit, iOS 15)
Tried to ask as a comment in the other thread: https://developer.apple.com/forums/thread/650386?answerId=628394022#reply-to-this-question But can't leave a comment in there for some reason (the thread is locked?). Asking exactly the same question, now for iOS 15. Anything changed in this area? When selecting a stroke path for object on PKCanvas, the option "Snap to Shape" appears. I understand this function is still in beta and has not made available natively to other PencilKit app. Is there a way using Stroke API to call this function directly after the user hold pencil for half a second when stroke is done drawing, just like how it behaves in native apps?
1
1
2.2k
Sep ’22
PencilKit new tools only available for some developers
Hello, I was trying to use the new Pencilkit tools watercolor, monoline fountainpen but there is no way to implement them in Xcode. There is even a Link to Apples documentation but it's not accessible in Xcode somehow. https://developer.apple.com/documentation/pencilkit/pkinkingtool/inktype/monoline?language=o_9 First I thought they did the same thing like back in the days where they added the shape recognition feature and then removed it after a few weeks. !!But it looks like as if some apps have access to this new tools for example PRODRAFTS ... How is that possible ?? !!
Replies
1
Boosts
2
Views
1.4k
Activity
Jan ’23
pencil kit issue--drawing can't stay on canvas
I want to use pencil kit in my swiftui app. I encapsulate PKCanvasView in UIViewRepresentable. I can draw on canvas with only one stroke. However, the image will disappear immediately when I release the finger. Am I missing anything? import SwiftUI import PencilKit struct ContentView: View { var body: some View { CanvasView() } } struct CanvasView: UIViewRepresentable { func makeUIView(context: Context) -> PKCanvasView { let canvas = PKCanvasView() canvas.tool = PKInkingTool(.pen, color: .green, width: 10) canvas.drawingPolicy = .anyInput return canvas } func updateUIView(_ uiView: PKCanvasView, context: Context) { } }
Replies
1
Boosts
1
Views
1.4k
Activity
Dec ’22
PencilKit '.monoline' as a PKInkingTool.InkType suddenly doesn't work anymore
Hello Guys, I am writing a program using PencilKit. Yesterday, everything worked fine with this line: @State var pencilStyle: PKInkingTool.InkType = .monoline But today, i am getting this Error: Type 'PKInkingTool.InkType' has no member 'monoline'" When I started Xcode Today, it downloaded a new Simulator for iOS 16.2. How can I fix this issue? I can't use my Projekt without fixing this... Thanks in advance <3
Replies
0
Boosts
1
Views
1k
Activity
Dec ’22
Why doesn't PKStroke conform to Hashable?
I want to work directly with PKStrokes in my app. To transform and change them individually. By one or by grouping them. I thought a perfect way of keeping track of them is to put them in a Set<PKStroke>. By doing this I receive an error: "Type 'PKStroke' does not conform to protocol 'Hashable'". Correct me if I'm wrong, but aren't all PKStrokes unique? Thus they should be eligible to be kept in a Set? What is a correct way of accessing/grouping/storing PKStrokes then? Manually searching for them in canvasView.drawing.strokes? Thank you very much!
Replies
0
Boosts
1
Views
976
Activity
Dec ’22
How to allowsFingerDrawing using PencilKit
Xcode showing me warning 'allowsFingerDrawing' was deprecated in iOS 14.0: Use 'drawingPolicy' property.
Replies
1
Boosts
0
Views
991
Activity
Dec ’22
How to make a canvas that can slide down infinitely like the Notes app with PencilKit?
I tried to set the contentSize of the PKCanvasView to CGSize(width: .max, height: .max), but it could be slide horizontally, which is not what I like. Besides, setting the width to a constant value is useless, it’ll make it unable to write because of the height is infinity. So how to deal with it?
Replies
0
Boosts
0
Views
1.1k
Activity
Nov ’22
PencilKit SwiftUI issue (disappearing strokes) on iOS 16 Simulator
We are using a SwiftUI view backed by PencilKit and are experiencing an issue on iOS 16 where drawn strokes disappear from the drawing (the drawing is empty after the stroke ends). Debugging the issue shows that PKCanvasView's drawing collection of strokes is increasing, yet they are not being rendered. Details: I'm on macOS 12.6 Monterey The bug surfaces in Xcode 14.1 / iOS 16.1 (I didn't check the Xcode 14.0 / 14.0.1). The code works as expected in Xcode 13.4.1 / iOS 15.5. The bug appears not to happen on device (iPhone 13 Pro / iOS 16.1.1) Example code demonstrating the issue: I have added a couple of print statements to show what is happening and to count the brush strokes of the PKDrawing. Please see the attached GIFs below that demonstrate the issue. import SwiftUI import PencilKit public struct TestCanvas {     private static let defaultTool = PKInkingTool(.pen, color: .darkGray, width: 5) } // MARK: UIViewRepresentable extension TestCanvas: UIViewRepresentable {     public func makeUIView(context: Context) -> some UIView {         print("make ui view")         let canvasView = PKCanvasView()         canvasView.delegate = context.coordinator         canvasView.drawingPolicy = .anyInput         canvasView.tool = Self.defaultTool         canvasView.isRulerActive = false         canvasView.backgroundColor = .clear         canvasView.isOpaque = true         return canvasView     }     public func updateUIView(_ uiView: UIViewType, context: Context) {         print("update ui view")     }     public func makeCoordinator() -> Coordinator {         Coordinator(self)     } } // MARK: Coordinator public extension TestCanvas {     @MainActor final class Coordinator: NSObject {         private let parent: TestCanvas         init(_ parent: TestCanvas) {             print("init coordinator")             self.parent = parent             super.init()         }     } } // MARK: PKCanvasViewDelegate extension TestCanvas.Coordinator: PKCanvasViewDelegate {     public func canvasViewDidEndUsingTool(_ canvasView: PKCanvasView) {         print("canvas did end using tool (\(canvasView.drawing.strokes.count) strokes)")     }     public func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) {         print("drawing did change (\(canvasView.drawing.strokes.count) strokes)")     } } Xcode 14.1 / iOS 16.1 PencilKit issue occurs on Xcode 14.1 / iOS 16.1 Simulator. Note the strokes disappear, yet the drawing's strokes keep incrementing. Xcode 13.4.1 / iOS 15.5 It works fine in Xcode 13.4.1 / iOS 15.5 Simulator. iPhone 13 Pro / iOS 16.1.1 I don't experience the issue on device (iPhone 13 Pro, iOS 16.1.1).
Replies
3
Boosts
1
Views
2.8k
Activity
Nov ’22
XCode 14, iOS 16 Simulator PencilKit functionality Bug
in iOS 16 simulator, Open default photo app - [Edit] Draw a path with PencilKit. The path is removed after mouse pointer up immediately. It seems to there is a bug in iOS16 simulator..
Replies
2
Boosts
3
Views
1.5k
Activity
Nov ’22
PKInkingTool markups getting disappeared
When drawing using PKInkingTool as soon as the drawing is finished markups getting disappear this happens in IOS 16 Xcode 14.1 Beta
Replies
2
Boosts
4
Views
1.4k
Activity
Nov ’22
PKCanvasView broken on iOS 16?
I have a PKCanvasView in my app where the user can draw, very simple, no use of pencils or toolpickers, just a straight up signature drawing. For some reason, on iOS 16, the canvas seems to be broken, meaning the drawing disappears as soon as the user lifts their finger. The canvas still holds the drawing in its memory, as evidenced by the drawings raw size increasing with every finger stroke, but the drawing is never actually shown. It seems a lot of people using PKCanvasView are complaining about this all over the internet right now, does anyone have a workaround? Is there a way to make Apple aware of this?
Replies
0
Boosts
2
Views
1k
Activity
Nov ’22
Scrollable PKCanvasView with SwiftUI subview
I found this question on stackoverflow with this source code as possible solution. How can I use a SwiftUI view instead of a UIImageView as underlayView? I tried to replace the UIImageView with a UIView and converted my SwiftUI view with a UIHostingController to a UIView but this UIView was then invisible in the PKCanvasView.
Replies
0
Boosts
0
Views
1.3k
Activity
Nov ’22
PKInkingTool markups getting disappeared
When drawing using PKInkingTool as soon as the drawing is finished markups getting disappear this happens in IOS 16 after Xcode 14 releases including Xcode 14 This cannot be simulated when built by Xcode 13.4
Replies
1
Boosts
0
Views
1.2k
Activity
Nov ’22
PencilKit: Get eraser size?
I can't find a way to get/set the eraser size of a PKCanvasView. Since I could get/set the width of a PKInkingTool, I expected to be able to do the same for a PKEraserTool. Am I missing something?
Replies
1
Boosts
0
Views
2k
Activity
Nov ’22
Overriding / modifying the default PencilKit edit menu?
Is it possible to override or add buttons to this menu, which appears when I tap on a PKCanvasView?
Replies
2
Boosts
1
Views
1.8k
Activity
Oct ’22
Unable to set PKInk color to black
For some reasons I am unable to set PKInk color to black. It works with yellow, red, blue, …but black is just ignored and I get the stroke in white. This is really weird and I don’t know why. I tried by setting black to PKInkingTool and even by creating a stroke manually and set the PKInk color to black. Do you have an idea? Thanks.
Replies
1
Boosts
0
Views
1.8k
Activity
Oct ’22
Color intensity increases when converting PKDrawing data to uiimage
I am trying to convert PKDrawing data to uiimage. Thus I've used apple's API PKDrawing data to uiimage. But the colour intensity of the converted image increases surprisingly. I mean there is a difference between the canvas data and the converted uiimage. What could be the reason behind that? Here is the scenario Preview Drawing Data on CanvasView Preview after converting Drawing Data to uiimage
Replies
1
Boosts
0
Views
1.1k
Activity
Oct ’22
Random crashing issue with PencilKit
Hi, in my app I don't use PencilKit anywhere, yet I keep getting the following crash: Pencil Kit Crash.txt I don't even know where to start in debugging this. Could this be a bug within UIKit? It obviously only occurs in iPad devices and so far not in iOS16, but that may just be because of sample size. Do I need to handle touches differently for when a user uses an Apple Pen? Any help is appreciated. Thanks.
Replies
1
Boosts
0
Views
1.2k
Activity
Oct ’22
PencilKit PKInkingTool Patternimage
I am trying to use a patternimage to define my color of the PKInkingTool for PencilKit. However, I am not getting any colors when I draw my stroke on the iPad. Is this a bug?
Replies
0
Boosts
0
Views
815
Activity
Oct ’22
Shape detection for other apps? (PencilKit, iOS 15)
Tried to ask as a comment in the other thread: https://developer.apple.com/forums/thread/650386?answerId=628394022#reply-to-this-question But can't leave a comment in there for some reason (the thread is locked?). Asking exactly the same question, now for iOS 15. Anything changed in this area? When selecting a stroke path for object on PKCanvas, the option "Snap to Shape" appears. I understand this function is still in beta and has not made available natively to other PencilKit app. Is there a way using Stroke API to call this function directly after the user hold pencil for half a second when stroke is done drawing, just like how it behaves in native apps?
Replies
1
Boosts
1
Views
2.2k
Activity
Sep ’22
Does Apple's PencilKit support that Drawing and Holding to Create Perfect Shapes, if not, how to implement it?
Does Apple's PencilKit support that Drawing and Holding to Create Perfect Shapes, if not, how to implement it?
Replies
0
Boosts
0
Views
1.2k
Activity
Sep ’22