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

131 Posts

Post

Replies

Boosts

Views

Activity

How to create multiple layers in PKCanvasView?
How can I use PKCanvasView in PencilKit to create multiple layers? These views are superimposed on each other. I want the drawing of each layer is kept independent from each other. It's also important that when the user uses the drag or zoom gesture on it, all layers MUST be scaled or dragged at the same time. Please provide a more concise, efficient and appropriate code implementation. Thanks.
0
1
1.3k
Mar ’23
How to increase the width of PencilKit .pen stroke?
The default PKInkingTool with inkType .pen seems to be limited in its stroke width. With a maximum width of around 25.66. Why is that? How can I increase it? Example code: canvasView.tool = PKInkingTool(.pen, color: .black, width: 10) print(canvasView.tool) //Prints: PKInkingTool(tool: <PKInkingTool: 0x2837ba140 com.apple.ink.pen color=UIExtendedSRGBColorSpace 0 0 0 1 width=10.000000>) canvasView.tool = PKInkingTool(.pen, color: .black, width: 20) //Prints: PKInkingTool(tool: <PKInkingTool: 0x282730140 com.apple.ink.pen color=UIExtendedSRGBColorSpace 0 0 0 1 width=20.000000>) //Problem starts here: canvasView.tool = PKInkingTool(.pen, color: .black, width: 30) //Prints: PKInkingTool(tool: <PKInkingTool: 0x28077a0c0 com.apple.ink.pen color=UIExtendedSRGBColorSpace 0 0 0 1 width=25.659260>) canvasView.tool = PKInkingTool(.pen, color: .black, width: 100) //Prints: PKInkingTool(tool: <PKInkingTool: 0x2824e08e0 com.apple.ink.pen color=UIExtendedSRGBColorSpace 0 0 0 1 width=25.659260>) How can I increase the stroke width? 🤔
2
0
1.5k
Feb ’23
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.5k
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.5k
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
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
1k
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.9k
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
1.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.9k
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.2k
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
How to create multiple layers in PKCanvasView?
How can I use PKCanvasView in PencilKit to create multiple layers? These views are superimposed on each other. I want the drawing of each layer is kept independent from each other. It's also important that when the user uses the drag or zoom gesture on it, all layers MUST be scaled or dragged at the same time. Please provide a more concise, efficient and appropriate code implementation. Thanks.
Replies
0
Boosts
1
Views
1.3k
Activity
Mar ’23
How to increase the width of PencilKit .pen stroke?
The default PKInkingTool with inkType .pen seems to be limited in its stroke width. With a maximum width of around 25.66. Why is that? How can I increase it? Example code: canvasView.tool = PKInkingTool(.pen, color: .black, width: 10) print(canvasView.tool) //Prints: PKInkingTool(tool: <PKInkingTool: 0x2837ba140 com.apple.ink.pen color=UIExtendedSRGBColorSpace 0 0 0 1 width=10.000000>) canvasView.tool = PKInkingTool(.pen, color: .black, width: 20) //Prints: PKInkingTool(tool: <PKInkingTool: 0x282730140 com.apple.ink.pen color=UIExtendedSRGBColorSpace 0 0 0 1 width=20.000000>) //Problem starts here: canvasView.tool = PKInkingTool(.pen, color: .black, width: 30) //Prints: PKInkingTool(tool: <PKInkingTool: 0x28077a0c0 com.apple.ink.pen color=UIExtendedSRGBColorSpace 0 0 0 1 width=25.659260>) canvasView.tool = PKInkingTool(.pen, color: .black, width: 100) //Prints: PKInkingTool(tool: <PKInkingTool: 0x2824e08e0 com.apple.ink.pen color=UIExtendedSRGBColorSpace 0 0 0 1 width=25.659260>) How can I increase the stroke width? 🤔
Replies
2
Boosts
0
Views
1.5k
Activity
Feb ’23
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.5k
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.5k
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
1.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
1k
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.9k
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
1.1k
Activity
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.
Replies
1
Boosts
0
Views
1.9k
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.2k
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