PencilKit PKStrokePointのサイズ
PKStrokePoint
init(location:timeOffset:size:opacity:force:azimuth:altitude:)
size:The size of this point.
Example Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | func strokeRectangle ( location : CGPoint ) { let size : CGFloat = 8 let x = location . x - ( size / 2 ) let y = location . y - ( size / 2 ) let pointArrays = [ [ CGPoint ( x : x , y : y ), CGPoint ( x : x + size , y : y ), CGPoint ( x : x + size , y : y + size ), CGPoint ( x : x , y : y + size ), CGPoint ( x : x , y : y )], ] let pKTool = self . tool if let pKInkingTool = pKTool as ? PKInkingTool { let color = pKInkingTool . color let ink = PKInk (. pen , color : color ) var strokes : [ PKStroke ] = [] for points in pointArrays where points . count > 1 { let strokePoints = points . enumerated (). map { index , point in PKStrokePoint ( location : point , timeOffset : 0.1 * TimeInterval ( index ), size : CGSize ( width : 1.8 , height : 1.8 ), opacity : 1 , force : 1 , azimuth : 0 , altitude : 0 ) } var startStrokePoint = strokePoints . first ! for strokePoint in strokePoints { let path = PKStrokePath ( controlPoints : [ startStrokePoint , strokePoint ], creationDate : Date ()) strokes . append ( PKStroke ( ink : ink , path : path )) startStrokePoint = strokePoint } } print ( "strokes:\( strokes . count )" ) self . drawing . strokes . append ( contentsOf : strokes ) self . undoManager !. registerUndo ( withTarget : self , selector : # selector ( undoStrocke ), object : self . drawing . strokes ) } } @objc func undoStrocke () { for _ in 1 ... 5 { self . drawing . strokes . removeLast () } } |