// // ContentView.swift // MyQrCode // // Created by dev on 2025/8/19. // import SwiftUI import QRCode struct ContentView: View { @State private var showScanner = false @State private var scannedCode: String? var body: some View { NavigationView { VStack(spacing: 30) { Image(systemName: "qrcode.viewfinder") .font(.system(size: 100)) .foregroundColor(.blue) Text("条码扫描器") .font(.largeTitle) .fontWeight(.bold) if let code = scannedCode { VStack(spacing: 10) { Text("扫描结果:") .font(.headline) Text(code) .font(.body) .padding() .background(Color.gray.opacity(0.1)) .cornerRadius(8) } } Button(action: { showScanner = true }) { HStack { Image(systemName: "camera") Text("开始扫描") } .font(.title2) .foregroundColor(.white) .padding() .background(Color.blue) .cornerRadius(10) } Spacer() } .padding() .navigationTitle("MyQrCode") .sheet(isPresented: $showScanner) { ScannerView() .onReceive(NotificationCenter.default.publisher(for: .scannerDidScanCode)) { notification in if let code = notification.object as? String { scannedCode = code showScanner = false } } } } } } #Preview { ContentView() }