MBDocCapture
MBDocCapture 使得在 iOS 应用中添加文档扫描功能变得简单,同时也支持图像编辑(裁剪和对比度增强)。
功能
- 文档扫描
- 照片裁剪和增强
- 自动扫描
演示
需求
- Swift 4.2
- iOS 10.0+
安装
Cocoapods
CocoaPods 是 Cocoa 项目的依赖管理器。
使用 CocoaPods 将 MBDocCapture 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'MBDocCapture'
end
然后,运行以下命令
$ pod install
用法
Swift
- 请确保您的视图控制器符合
ImageScannerControllerDelegate
协议
class YourViewController: UIViewController, ImageScannerControllerDelegate {
// YourViewController code here
}
- 在您的视图控制器中实现委托函数
/// Tells the delegate that the user scanned a document.
///
/// - Parameters:
/// - scanner: The scanner controller object managing the scanning interface.
/// - results: The results of the user scanning with the camera.
/// - Discussion: Your delegate's implementation of this method should dismiss the image scanner controller.
func imageScannerController(_ scanner: ImageScannerController, didFinishScanningWithResults results: ImageScannerResults) {
scanner.dismiss()
}
/// Tells the delegate that the user scanned a document.
///
/// - Parameters:
/// - scanner: The scanner controller object managing the scanning interface.
/// - page1Results: The results of the user scanning page 1.
/// - page2Results: The results of the user scanning page 2.
/// - Discussion: Your delegate's implementation of this method should dismiss the image scanner controller.
func imageScannerController(_ scanner: ImageScannerController, didFinishScanningWithPage1Results page1Results: ImageScannerResults, andPage2Results page2Results: ImageScannerResults) {
scanner.dismiss()
}
/// Tells the delegate that the user cancelled the scan operation.
///
/// - Parameters:
/// - scanner: The scanner controller object managing the scanning interface.
/// - Discussion: Your delegate's implementation of this method should dismiss the image scanner controller.
func imageScannerControllerDidCancel(_ scanner: ImageScannerController) {
scanner.dismiss()
}
/// Tells the delegate that an error occured during the user's scanning experience.
///
/// - Parameters:
/// - scanner: The scanner controller object managing the scanning interface.
/// - error: The error that occured.
func imageScannerController(_ scanner: ImageScannerController, didFailWithError error: Error) {
scanner.dismiss()
}
- 最后,在您的视图控制器中某个位置创建并展示一个
ImageScannerController
实例
let scannerViewController = ImageScannerController(delegate: self)
//scannerViewController.shouldScanTwoFaces = false // Use this to scan the front and the back of a document
present(scannerViewController, animated: true)
许可
MBDocCapture 采用 MIT 许可证发布。有关更多信息,请参阅 LICENSE 文件。
支持
如果这个项目帮助了您,请买我一杯咖啡