Post

Replies

Boosts

Views

Activity

Retrieve Apple Pencil Pro Orientation, Roll outside of HoverPose?
I'm attempting to retrieve the values of the Pencil Pro using the new PencilHoverPose, however according to the documentation it appears these can only be accessed while in a hover state (0 to ~0.5" from the screen). Is there a way to get the orientation or roll values of the Apple Pencil Pro outside of a hover? I'm attempting to use the pencil as an input device, necessitating it be farther from the screen than 0.5" Below is a simple view I'm using to display the available values: import SwiftUI import UIKit struct PencilSqueezeView: View { @State private var squeezeText: String = "Squeeze the Apple Pencil Pro" @State private var hoverDistance: CGFloat = 0.0 @State private var anchor: UnitPoint = .center @State private var location: CGPoint = .zero @State private var altitude: Angle = .degrees(0) @State private var azimuth: Angle = .degrees(0) @State private var roll: Angle = .degrees(0) var body: some View { VStack { Text(squeezeText) .font(.largeTitle) .padding() Text("Hover Distance: \(String(format: "%.2f", hoverDistance))") .font(.title2) .padding() Text("Anchor: \(anchor)") .font(.title2) .padding() Text("Location: \(location.x), \(location.y)") .font(.title2) .padding() Text("Altitude: \(altitude.degrees)°") .font(.title2) .padding() Text("Azimuth: \(azimuth.degrees)°") .font(.title2) .padding() Text("Roll: \(roll.degrees)°") .font(.title2) .padding() Spacer() } .onPencilSqueeze { phase in handlePencilSqueeze(phase: phase) if case let .ended(value) = phase { if let hoverPose = value.hoverPose { updateHoverPose(hoverPose) } else { print("hoverPose is nil") } } } .padding() } private func handlePencilSqueeze(phase: PencilSqueezeGesturePhase) { switch phase { case .active: squeezeText = "Squeeze began" case .ended: squeezeText = "Squeeze ended" case .failed: squeezeText = "Squeeze failed" } } private func updateHoverPose(_ hoverPose: PencilHoverPose) { hoverDistance = hoverPose.zDistance anchor = hoverPose.anchor location = hoverPose.location altitude = hoverPose.altitude azimuth = hoverPose.azimuth roll = hoverPose.roll print("zDistance: \(hoverPose.zDistance)") print("anchor: \(hoverPose.anchor)") print("location: \(hoverPose.location)") print("altitude: \(hoverPose.altitude)") print("azimuth: \(hoverPose.azimuth)") print("roll: \(hoverPose.roll)") } }
1
0
486
May ’24