iOS: sichtbarer Fokus-Rahmen beim Antippen der Kamera
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user