Hello,
I have a custom 3D object viewer on iOS that lets users spin the model using the touchscreen or a trackpad and supports coasting (momentum spinning). I need to stop the coasting animation as soon as the user touches down, but I can only immediately detect touches on the screen itself - on the trackpad I can't get an immediate notification of the touches.
So far I’ve tried:
State.began on my UIPanGestureRecognizer. It only fires after a small movement on both touchscreen and trackpad.
.possible on the pan gesture; this state never occurs during the gesture cycle.
UIApplicationSupportsIndirectInputEvents = YES in Info.plist; it didn’t make touchesBegan fire for indirectPointer touches.
Since UITableView (and other UIScrollView subclasses) clearly detect trackpad “touch-down” to cancel scrolling, there must be a way to receive that event. Does anyone know how to catch the initial trackpad contact—before any movement—on an indirect input device?
Below is a minimal code snippet demonstrating the issue. On the touchscreen you'll see a message the moment you touch the view, but the trackpad doesn't trigger any messages until your fingers move. Any advice would be greatly appreciated.
Thanks in advance,
John
import UIKit
class ViewController: UIViewController {
private let debugView = DebugView()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// Fill the screen with our debug view
debugView.frame = view.bounds
debugView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
debugView.backgroundColor = UIColor(white: 0.95, alpha: 1)
view.addSubview(debugView)
// Attach a pan recognizer that logs its state
let panGR = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))
panGR.allowedScrollTypesMask = .all
debugView.addGestureRecognizer(panGR)
}
@objc private func handlePan(_ gr: UIPanGestureRecognizer) {
switch gr.state {
case .possible:
print("Pan state: possible")
case .began:
print("Pan state: began")
case .changed:
print("Pan state: changed – translation = \(gr.translation(in: debugView))")
case .ended:
print("Pan state: ended – velocity = \(gr.velocity(in: debugView))")
case .cancelled:
print("Pan state: cancelled")
case .failed:
print("Pan state: failed")
@unknown default:
print("Pan state: unknown")
}
}
}
class DebugView: UIView {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
for t in touches {
let typeDesc: String
switch t.type {
case .direct: typeDesc = "direct (finger)"
case .indirectPointer: typeDesc = "indirectPointer (trackpad/mouse)"
case .indirect: typeDesc = "indirect (Apple TV remote)"
case .pencil: typeDesc = "pencil (Apple Pencil)"
@unknown default: typeDesc = "unknown"
}
print("touchesBegan on DebugView – touch type: \(typeDesc), location: \(t.location(in: self))")
}
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Everything seems to work fine when I upload my app using Xcode 13.0, but very soon after the upload successfully completes I get this email from Apple:
Dear Developer,
We identified one or more issues with a recent delivery for your app, "MyApp" 1.0.0 (2021.10.24.1). Please correct the following issues, then upload again.
Best regards,
The App Store Team
The email names no issues, and the builds page for my app at appstoreconnect.apple.com doesn't show my upload at all, not even as failed.
The last time I uploaded a build was about a month ago, and it worked fine. I suspect Xcode was auto-updated to 13.0 since my last upload and that's the source of the problem, but I have no clues to go on. How can I figure out what's going wrong?