Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Apple Pencil対応の勘所を話します

Shetommy
September 19, 2020

Apple Pencil対応の勘所を話します

iOSDC Japan 2020にて発表したスライドです。

https://fortee.jp/iosdc-japan-2020/proposal/348c2d74-7855-4d8b-8457-db9df25f9a7c

Shetommy

September 19, 2020
Tweet

More Decks by Shetommy

Other Decks in Technology

Transcript

  1.  -JLF1BQFS͸ͲΜͳΞϓϦ͔  ͳ͔ͥͭͬͨ͘  1FODJM,JUͱ͸  1FODJM,JUͰͰ͖Δ͜ͱͰ͖ͳ͍͜ͱ  1,$BOWBT7JFXͱ1,%SBXJOH

     ࡾߦͰಋೖͰ͖Δ1,$BOWBT7JFX  1,%SBXJOHͷѻ͍ํ  1,5PPM1JDLFSͷσβΠϯ͸͋·ΓΧελϚΠζ͕ޮ͔ͳ͍  μʔΫϞʔυରԠͷ᠘  ແݶεΫϩʔϧ࢓༷  ʢ͓·͚ʣ"QQMF1FODJMରԠͷྺ࢙
  2. Ͱ͖Δ͜ͱ w "QQMF७ਖ਼ͷϝϞΞϓϦͷ6*Λ࣮ݱ͢Δ w $BOWBT w 5PPM1JDLFSVOEPSFEP ϖϯফ͠ΰϜఆن ৭มߋ w

    1,%SBXJOHͱ6**NBHF%BUBܕͷ૬ޓม׵Λ͢Δ w ࢦͱ"QQMF1FODJMͷλονΛࣝผ͢Δ ɹʢͨͩ͠BMMPXT'JOHFS%SBXJOH͕J04͔Β%FQSFDBUFEʹͳ͍ͬͯΔʣ w %FMFHBUFϝιουܦ༝ͰESBXJOHͷมߋɺ 5PPM1JDLFSͷ࢖༻ͷTUBSUFOEΛݕ஌͢Δ
  3. 1,$BOWBT7JFX 1,%SBXJOH 7JFX .PEFM πʔϧ 1,5PPM1JDLFS 1,%SBXJOH 1,%SBXJOH 1,*OLJOH5PPM PKToolPickerObserver

    (protocol) 1,&SBTFS5PPM 1,-BTTP5PPM 1,5PPM .selectedTool ˞1,$BOWBT7JFXͷAUPPMAʹ௚ࢦఆ΋Մ
  4. %BUBͰͦͷ··อଘ͢Δͷ͸ѱख w 1,%SBXJOH͕ෳ਺ʹͳΔͱɺ%BUBͩͱϝλσʔλΛѻ͍੾Εͳ͍ ʢFYʣॱংɺඳ͍ͨ೔࣌ɺछྨͳͲ w ެࣜαϯϓϧͩͱҰݸט·͍ͤͯͨͷͰɺͦΕʹͳΒͬͨ struct DataModel: Codable {

    /// Names of the drawing assets to be used to initialize the data model the first time. static let defaultDrawingNames: [String] = ["Notes"] /// The width used for drawing canvases. static let canvasWidth: CGFloat = 768 /// The drawings that make up the current data model. var drawings: [PKDrawing] = [] var signature = PKDrawing() }
  5. 1,5PPM1JDLFSͷઃఆྫ private func addPalette() { if let window = UIApplication.shared.windows.first,

    let toolPicker = PKToolPicker.shared(for: window) { self.toolPicker = toolPicker self.toolPicker.addObserver(canvasView) self.toolPicker.addObserver(self) canvasView.becomeFirstResponder() self.toolPicker.selectedTool = PKInkingTool(.pen, color: .black, width: 1) } }
  6. Կ͕ى͖ͨʁ w $PMMFDUJPO7JFXʹԼهͷΑ͏ʹϊʔτΛද͍ࣔͯͨ͠ let drawing = drawings[indexPath.row] let image =

    drawing.image(from: drawing.bounds, scale: 1.0) w දࣔޙʹϥΠτϞʔυμʔΫϞʔυͷ੾Γସ͕͑ى͜Δͱɺ ɹ৭൓స͕ߦ͑ͣɺݟ͑ͳ͘ͳͬͯ͠·͏
  7. override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { if previousTraitCollection?.userInterfaceStyle != traitCollection.userInterfaceStyle

    { reload() } } w ରࡦˣ w ͳ͓ڞ༗ػೳͰόά͕·ͩ࢒͍ͬͯΔʜʜ w 1FODJM,JUʹμʔΫϞʔυରԠ͓೚ͤͰ͖ΔΑ͏Ͱ ɹ࣮͸΍Βͳ͖Ό͍͚ͳ͍͜ͱ͕͋Δ
  8. // MARK: Canvas View Delegate /// Delegate method: Note that

    the drawing has changed. func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) { hasModifiedDrawing = true updateContentSizeForDrawing() } /// Helper method to set a suitable content size for the canvas view. func updateContentSizeForDrawing() { // Update the content size to match the drawing. let drawing = canvasView.drawing let contentHeight: CGFloat // Adjust the content size to always be bigger than the drawing height. if !drawing.bounds.isNull { contentHeight = max(canvasView.bounds.height, (drawing.bounds.maxY + DrawingViewController.canvasOverscrollHeight) * canvasView.zoomScale) } else { contentHeight = canvasView.bounds.height } canvasView.contentSize = CGSize(width: DataModel.canvasWidth * canvasView.zoomScale, height: contentHeight) } ˞88%$ͷαϯϓϧΑΓ