From 944edbccd0859378007ab00cf974bcc04e125d90 Mon Sep 17 00:00:00 2001 From: Scarriffle Date: Sun, 26 Jul 2026 22:27:52 +0200 Subject: [PATCH] iOS: sichtbarer Fokus-Rahmen beim Antippen der Kamera MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tap-to-Focus war bereits verdrahtet, aber ohne sichtbare Rueckmeldung – daher wirkte es, als passiere nichts. Beim Antippen erscheint jetzt kurz ein gelber Fokus-Rahmen an der getippten Stelle (wie in der System-Kamera); die Kamera stellt weiterhin gezielt dorthin scharf. Co-Authored-By: Claude Opus 4.8 --- ios/Sources/ScannerView.swift | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ios/Sources/ScannerView.swift b/ios/Sources/ScannerView.swift index 31bef8f..d98329f 100644 --- a/ios/Sources/ScannerView.swift +++ b/ios/Sources/ScannerView.swift @@ -145,10 +145,13 @@ final class ScannerViewController: UIViewController, AVCaptureMetadataOutputObje } /// Antippen stellt gezielt auf den Code scharf - Rettungsanker fuer Codes, - /// die der Autofokus nicht von selbst findet. + /// die der Autofokus nicht von selbst findet. Ein kurz aufblitzender Rahmen + /// zeigt, wohin fokussiert wird (wie in der System-Kamera). @objc private func focusOnTap(_ gesture: UITapGestureRecognizer) { + let location = gesture.location(in: view) + showFocusIndicator(at: location) guard let device, let preview else { return } - let point = preview.captureDevicePointConverted(fromLayerPoint: gesture.location(in: view)) + let point = preview.captureDevicePointConverted(fromLayerPoint: location) guard (try? device.lockForConfiguration()) != nil else { return } if device.isFocusPointOfInterestSupported, device.isFocusModeSupported(.autoFocus) { device.focusPointOfInterest = point @@ -161,6 +164,30 @@ final class ScannerViewController: UIViewController, AVCaptureMetadataOutputObje device.unlockForConfiguration() } + /// Kurzer gelber Fokus-Rahmen an der getippten Stelle als Rueckmeldung. + private func showFocusIndicator(at point: CGPoint) { + let seite: CGFloat = 72 + let rahmen = UIView(frame: CGRect(x: 0, y: 0, width: seite, height: seite)) + rahmen.center = point + rahmen.backgroundColor = .clear + rahmen.isUserInteractionEnabled = false + rahmen.layer.borderColor = UIColor.systemYellow.cgColor + rahmen.layer.borderWidth = 1.5 + rahmen.layer.cornerRadius = 6 + rahmen.alpha = 0 + rahmen.transform = CGAffineTransform(scaleX: 1.4, y: 1.4) + view.addSubview(rahmen) + + UIView.animate(withDuration: 0.2, animations: { + rahmen.alpha = 1 + rahmen.transform = .identity + }, completion: { _ in + UIView.animate(withDuration: 0.35, delay: 0.6, options: [], animations: { + rahmen.alpha = 0 + }, completion: { _ in rahmen.removeFromSuperview() }) + }) + } + /// Licht an: hebt den Kontrast bei matten oder farbigen Codes deutlich. func setTorch(on: Bool) { guard let device, device.hasTorch, device.isTorchAvailable else { return }