我观看了 WWDC 会议及其示例项目:https://developer.apple.com/documentation/pencilkit/inspecting_modifying_and_constructing_pencilkit_drawings https://developer.apple.com/documentation/pencilkit/inspecting_modifying_and_constructing_pencilkit_drawings
然而,当我尝试在画布上绘制 CGPoints 时,什么也没有显示。
这是我的设置:
var points: [CGPoint] = []
(500...1000).forEach { x in
(500...1000).forEach { y in
points.append(CGPoint(x: x, y: y))
}
}
let strokePoints = points.map {
PKStrokePoint(location: $0, timeOffset: 0, size: CGSize(uniform: 1), opacity: 2, force: 1, azimuth: 1, altitude: 1)
}
let strokePath = PKStrokePath(controlPoints: strokePoints, creationDate: Date())
let stroke = PKStroke(ink: PKInk(.pen, color: .systemGreen), path: strokePath)
canvasView.drawing = PKDrawing(strokes: [ stroke ])
我认为问题出在我划水的大小上。这将起作用:
PKStrokePoint(location: point, timeOffset: 0, size: CGSize(uniform: 3), opacity: 1, force: 0, azimuth: 0, altitude: 0)
请注意,它必须至少为 3。如果为 1,则不可见,如果为 2,则半透明。这似乎与屏幕尺寸无关(我的iPad Pro的UIScreen.main.scale = 2.0
)所以我只是将其硬编码为 3,以表示单个像素。
为了实现这个结果,我使用铅笔在屏幕上绘制了一个像素并记录了其内容,这向我显示了以下参数:
▿ PencilKit.PKStrokePoint
- strokePoint: <PKStrokePoint: 0x600001ad8f60 location={445, 333.5} timeOffset=0.000000 size={3.084399938583374, 3.084399938583374} opacity=0.999985 azimuth=-3.141593 force=0.000000 altitude=1.570796> #0
- super: NSObject
然后我尝试了这些值(大小、不透明度、方位角、力和高度),并发现除了大小和不透明度之外,这些值都不重要。这就是为什么我在代码中将它们全部设置为零值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)