Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Swift 今更!?PencilKit

WWDC2020「PencilKitの新機能」を見て、PencilKitを使っていないと思い立ち始める。
PencilKitを使って作りたいものが過去からあり、そこに向かって、最初の最初、スタートライン前。

とりあえずPencilKitを使う

StoryBoardでPKCanvasView配置

alt

ViewController.swift

import UIKit
import PencilKit

class ViewController: UIViewController, PKToolPickerObserver {

    @IBOutlet weak var pkCanvasView: PKCanvasView!

    var toolPicker: PKToolPicker!

    override func viewDidLoad() {
        super.viewDidLoad()
        pkCanvasView.allowsFingerDrawing = false
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if let window = self.pkCanvasView.window {
            let toolPicker = PKToolPicker.shared(for: window)
            toolPicker?.addObserver(pkCanvasView)
            toolPicker?.setVisible(true, forFirstResponder: pkCanvasView)
            pkCanvasView.becomeFirstResponder()
            print("PKToolPicker Set")
        }
    }
}

これだけでここまで出来る

alt

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away