VisionLiveText_SwiftUICompatible
VisionLiveText_SwiftUICompatible copied to clipboard
WWDC 2022 / iOS 16で公開された新機能「ライブテキスト」のSwiftUIで使用されている互換ビュー。Compatible views used in SwiftUI for the new live text feature
Live Text - 画像テキスト認識 - SwiftUI互換ビュー
WWDC 2022 / iOS 16で公開された新機能「ライブテキスト」のSwiftUIで使用されている互換ビューです。 These are compatible views used in SwiftUI for the new live text feature released in WWDC 2022 / iOS 16.
| DataScannerView | ImageLiveTextView |
|---|---|
![]() |
![]() |
!! このフレームワークは、Xcode 14 betaとiOS 16のシミュレータ/デバイスで動作します。
DataScannerView
You can use the DataScannerView to use a live camera stream and scan for text or machine-readable codes. Found elements will be highlighted and selectable. (remember to add the permission to access the camera)
You will present this view with camera view.
DataScannerViewを使用すると、ライブカメラストリームを使用して、テキストまたは機械可読コードをスキャンすることができます。見つかった要素はハイライト表示され、選択することができます。(カメラへのアクセス権を追加することを忘れないでください)
カメラビューで表示されます。
// Button to start scanning
Button("Show scanning view") {
self.showScanningView = true
}
.sheet(isPresented: $showScanningView) {
NavigationStack {
DataScannerView(startScanning: $showScanningView,
tappedScanItem: $scannedItem)
}
}
You can check for device compatibility and disable the button when the device does not support this feature: .disabled(!(DataScannerViewController.isSupported && DataScannerViewController.isAvailable))
You may also need to add a button to close the scanner view:
デバイスの互換性をチェックして、デバイスがこの機能をサポートしていない場合はボタンを無効にすることができます: .disabled(!(DataScannerViewController.isSupported && DataScannerViewController.isAvailable))
また、スキャナビューを閉じるためのボタンを追加する必要があるかもしれません。
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Cancel") {
self.showScanningView = false
}
}
}
デモコードファイルをご覧ください。
ImageLiveTextView
You can also use the ImageLiveTextView to analyze an UIImage file. Users will be able to long-press to select the text recognized.
また、ImageLiveTextViewを使用してUIImageファイルを解析することができます。ユーザーは長押しで認識されたテキストを選択できるようになります。
if let pickedImageObject {
ImageLiveTextView(imageObject: pickedImageObject, analyzerConfiguration: .init(.text))
.frame(height: 500)
}
Here, pickedImageObject will contain the UIImage object the user picked.
ここで、 pickedImageObject にはユーザがピックした UIImage オブジェクトが入ります。
Remember to define a frame for the view. ビューのフレームを定義することを忘れないでください。
デモコードファイルをご覧ください。
使用方法
Swift Package Manager
- Xcode内からプロジェクトを開く
- 上部のシステムバーの"File"をクリック
- "Add Packages..."をクリック
- 以下のURLをペースト:
https://github.com/mszpro/VisionLiveText_SwiftUICompatible.git - Version: Up to Next Major
1.0 < - "Next"をクリック
- "Done"をクリック。
LICENSE
MIT LICENSE. You have to include the complete and unmodified contents within the LICENSE file of this project and make it visible to the end user.

