Search code examples
xcodeipadios-simulatorstylus-pen

Xcode iOS Simulator: can I use the mouse as pretend Apple Pencil input (on iPad Pro), for testing?


Is it possible to do this (with a menu, a shortcut, or a modifier key + mouse)?

For example, you can use the mouse to test simple touch gestures in the simulator, like left mouse acts as single finger, and shift / option allow for different two finger gestures.

I have been unable to find any documentation one way or the other about whether this is possible, despite this developer.apple.com page where the simple, easy-to-understand API changes for supporting Apple Pencil hardware are documented.

Do I need a physical iPad Pro + Pencil hardware to test my Pencil support?

(My app is not a drawing app, just an app where touch input should work with large touch targets and Pencil should allow finer distinctions.)


Solution

  • iOS 14

    #if targetEnvironment(simulator)
    canvasView.drawingPolicy = .anyInput
    #else
    canvasView.drawingPolicy = .pencilOnly
    #endif
    

    Also in the Settings app there is a global setting called "Only Draw with Apple Pencil". This can be read from UIPencilInteraction.prefersPencilOnlyDrawing in PencilKit.

    iOS 13 (only)

    #if targetEnvironment(simulator)
    canvasView.allowsFingerDrawing = true
    #else
    canvasView.allowsFingerDrawing = false
    #endif
    

    Courtesy of https://stackoverflow.com/a/62567169/2667933