diff --git a/DocumentScanner/Resources/CroppView.xib b/DocumentScanner/Resources/CroppView.xib index 552cb46..b12f34a 100644 --- a/DocumentScanner/Resources/CroppView.xib +++ b/DocumentScanner/Resources/CroppView.xib @@ -1,11 +1,9 @@ - - - - + + - + @@ -19,16 +17,16 @@ - + - + - + - + @@ -45,18 +43,18 @@ + - - - - - - - + + + + + + + - - + diff --git a/DocumentScanner/Resources/ScannerView.xib b/DocumentScanner/Resources/ScannerView.xib index 0943a6b..d7f6139 100644 --- a/DocumentScanner/Resources/ScannerView.xib +++ b/DocumentScanner/Resources/ScannerView.xib @@ -1,11 +1,9 @@ - - - - + + - + @@ -15,60 +13,46 @@ - - + - + - + - - - - - + + - - - - + - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/DocumentScanner/Source/DocScanner.swift b/DocumentScanner/Source/DocScanner.swift index 6d1c977..fc51c50 100644 --- a/DocumentScanner/Source/DocScanner.swift +++ b/DocumentScanner/Source/DocScanner.swift @@ -37,6 +37,9 @@ import UIKit /// If true can scan and export multiple documents at onse, defaults to false public var exportMultiple: Bool = false + + ///Maximum number of scans. -1 for unlimited + public var maximumScans = -1 /// Construct scanner object public init(presenter: UIViewController) { @@ -132,8 +135,17 @@ import UIKit // perform perspective correction if let flattened = photo.flattened(rect: self.camera.observationRect) { + self.scannedImages.append(flattened.noiseReducted.rotated) - + + if self.maximumScans != -1 + && self.scannedImages.count >= self.maximumScans { + self.exportMultiple ? self.exportImages?(self.scannedImages) : self.exportImage?(self.scannedImages[0]) + self.scannedImages.removeAll() + self.stopSession() + self.dismiss?() + } + return } @@ -146,6 +158,7 @@ import UIKit // return from manual cropping cropView.onRetake = { self.continueSession() + self.stopSession() } cropView.onRegionSave = { @@ -157,6 +170,14 @@ import UIKit if let flattened = photo.flattened(rect: region) { self.scannedImages.append(flattened.noiseReducted.rotated) + if self.maximumScans != -1 + && self.scannedImages.count >= self.maximumScans { + self.exportMultiple ? self.exportImages?(self.scannedImages) : self.exportImage?(self.scannedImages[0]) + self.scannedImages.removeAll() + self.stopSession() + self.dismiss?() + } + return } @@ -186,6 +207,14 @@ import UIKit let croppedImage = photo.crop(toPreviewLayer: camera.cameraLayer, withRect: regionRect) scannedImages.append(croppedImage.noiseReducted.rotated) + + if self.maximumScans != -1 + && self.scannedImages.count >= self.maximumScans { + self.exportMultiple ? self.exportImages?(self.scannedImages) : self.exportImage?(self.scannedImages[0]) + self.scannedImages.removeAll() + self.stopSession() + self.dismiss?() + } } private func toggleIdle(disabled: Bool) { diff --git a/DocumentScanner/Source/ScannerView.swift b/DocumentScanner/Source/ScannerView.swift index c863571..6c480bc 100644 --- a/DocumentScanner/Source/ScannerView.swift +++ b/DocumentScanner/Source/ScannerView.swift @@ -70,25 +70,11 @@ open class ScannerView: UIView { Utils.subscribeToDeviceOrientationNotifications(self, selector: #selector(deviceOrientationDidChange)) - let interface = UIApplication.shared.statusBarOrientation - - if case .portrait = interface { - if Utils.isIPhoneX { - menuViewHeight.constant = 100 - } - } + menuViewHeight.constant = self.safeAreaInsets.top } @objc private func deviceOrientationDidChange() { - let interface = UIApplication.shared.statusBarOrientation - - if interface.isLandscape { - menuViewHeight.constant = 44 - } else { - if Utils.isIPhoneX { - menuViewHeight.constant = 100 - } - } + menuViewHeight.constant = self.safeAreaInsets.top } func updateShapeLayer() { diff --git a/DocumentScanner/Source/Utils.swift b/DocumentScanner/Source/Utils.swift index e079c1b..2ddcde0 100644 --- a/DocumentScanner/Source/Utils.swift +++ b/DocumentScanner/Source/Utils.swift @@ -107,12 +107,4 @@ class Utils { return .scaleAspectFit } } - - static var isIPhoneX: Bool { - if UIDevice.current.userInterfaceIdiom == .phone { - return UIScreen.main.nativeBounds.height >= 1792 // iPhone XR - } - - return false - } } diff --git a/Example/DocumentScanner.xcodeproj/project.pbxproj b/Example/DocumentScanner.xcodeproj/project.pbxproj deleted file mode 100644 index ca1a949..0000000 --- a/Example/DocumentScanner.xcodeproj/project.pbxproj +++ /dev/null @@ -1,447 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 0AEC5413A72BF2D19D12D610 /* Pods_DocumentScanner_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A2EC1DEE3D8ABC815DA85D8A /* Pods_DocumentScanner_Example.framework */; }; - 441213CC1FE7EA96009B059D /* ScannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 441213CB1FE7EA96009B059D /* ScannerViewController.swift */; }; - 4480FEFA1FD0246F006D99B6 /* PreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4480FEF91FD0246E006D99B6 /* PreviewView.swift */; }; - 4480FEFC1FD02641006D99B6 /* PreviewView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4480FEFB1FD0248E006D99B6 /* PreviewView.xib */; }; - 449AFFB821186B8A001E856E /* DocumentScanner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 449AFFB721186B8A001E856E /* DocumentScanner.framework */; }; - 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; - 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; - 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; }; - 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; - 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 37222C1CD7B9DC95A0852BAC /* Pods-DocumentScanner_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocumentScanner_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-DocumentScanner_Example/Pods-DocumentScanner_Example.release.xcconfig"; sourceTree = ""; }; - 441213CB1FE7EA96009B059D /* ScannerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerViewController.swift; sourceTree = ""; }; - 4480FEF91FD0246E006D99B6 /* PreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewView.swift; sourceTree = ""; }; - 4480FEFB1FD0248E006D99B6 /* PreviewView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PreviewView.xib; sourceTree = ""; }; - 449AFFB721186B8A001E856E /* DocumentScanner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DocumentScanner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 449AFFCE21186FFD001E856E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 4EAFCCFA132284D03B9117A9 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; - 52859891900D9BE173454DD7 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; - 607FACD01AFB9204008FA782 /* DocumentScanner_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DocumentScanner_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; - 66FB1A44BD4A9996601D8A98 /* Pods-DocumentScanner_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocumentScanner_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-DocumentScanner_Example/Pods-DocumentScanner_Example.debug.xcconfig"; sourceTree = ""; }; - A2EC1DEE3D8ABC815DA85D8A /* Pods_DocumentScanner_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DocumentScanner_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - CB694B1C5523A4B31779C32F /* Pods-DocumentScanner_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocumentScanner_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-DocumentScanner_Tests/Pods-DocumentScanner_Tests.release.xcconfig"; sourceTree = ""; }; - DF0C732405658D1416611F5A /* DocumentScanner.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = DocumentScanner.podspec; path = ../DocumentScanner.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; - F9FD351EB3A3C7CD04E82DBC /* Pods-DocumentScanner_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocumentScanner_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-DocumentScanner_Tests/Pods-DocumentScanner_Tests.debug.xcconfig"; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 607FACCD1AFB9204008FA782 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 449AFFB821186B8A001E856E /* DocumentScanner.framework in Frameworks */, - 0AEC5413A72BF2D19D12D610 /* Pods_DocumentScanner_Example.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 607FACC71AFB9204008FA782 = { - isa = PBXGroup; - children = ( - 607FACF51AFB993E008FA782 /* Podspec Metadata */, - 607FACD21AFB9204008FA782 /* Example for DocumentScanner */, - 607FACD11AFB9204008FA782 /* Products */, - C0E73E76BD7851F19C1E946C /* Pods */, - AE74B06B09271251B07AC559 /* Frameworks */, - ); - sourceTree = ""; - }; - 607FACD11AFB9204008FA782 /* Products */ = { - isa = PBXGroup; - children = ( - 607FACD01AFB9204008FA782 /* DocumentScanner_Example.app */, - ); - name = Products; - sourceTree = ""; - }; - 607FACD21AFB9204008FA782 /* Example for DocumentScanner */ = { - isa = PBXGroup; - children = ( - 607FACD51AFB9204008FA782 /* AppDelegate.swift */, - 441213CB1FE7EA96009B059D /* ScannerViewController.swift */, - 4480FEF91FD0246E006D99B6 /* PreviewView.swift */, - 4480FEFB1FD0248E006D99B6 /* PreviewView.xib */, - 607FACD91AFB9204008FA782 /* Main.storyboard */, - 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, - 607FACDC1AFB9204008FA782 /* Images.xcassets */, - 607FACD71AFB9204008FA782 /* ViewController.swift */, - 607FACD31AFB9204008FA782 /* Supporting Files */, - ); - name = "Example for DocumentScanner"; - path = DocumentScanner; - sourceTree = ""; - }; - 607FACD31AFB9204008FA782 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 449AFFCE21186FFD001E856E /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 607FACF51AFB993E008FA782 /* Podspec Metadata */ = { - isa = PBXGroup; - children = ( - DF0C732405658D1416611F5A /* DocumentScanner.podspec */, - 52859891900D9BE173454DD7 /* README.md */, - 4EAFCCFA132284D03B9117A9 /* LICENSE */, - ); - name = "Podspec Metadata"; - sourceTree = ""; - }; - AE74B06B09271251B07AC559 /* Frameworks */ = { - isa = PBXGroup; - children = ( - 449AFFB721186B8A001E856E /* DocumentScanner.framework */, - A2EC1DEE3D8ABC815DA85D8A /* Pods_DocumentScanner_Example.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - C0E73E76BD7851F19C1E946C /* Pods */ = { - isa = PBXGroup; - children = ( - 66FB1A44BD4A9996601D8A98 /* Pods-DocumentScanner_Example.debug.xcconfig */, - 37222C1CD7B9DC95A0852BAC /* Pods-DocumentScanner_Example.release.xcconfig */, - F9FD351EB3A3C7CD04E82DBC /* Pods-DocumentScanner_Tests.debug.xcconfig */, - CB694B1C5523A4B31779C32F /* Pods-DocumentScanner_Tests.release.xcconfig */, - ); - name = Pods; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 607FACCF1AFB9204008FA782 /* DocumentScanner_Example */ = { - isa = PBXNativeTarget; - buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "DocumentScanner_Example" */; - buildPhases = ( - C73508E5663D8EC43FDB59FF /* [CP] Check Pods Manifest.lock */, - 607FACCC1AFB9204008FA782 /* Sources */, - 607FACCD1AFB9204008FA782 /* Frameworks */, - 607FACCE1AFB9204008FA782 /* Resources */, - 31C62B1BCE9B481190ABD96C /* [CP] Embed Pods Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = DocumentScanner_Example; - productName = DocumentScanner; - productReference = 607FACD01AFB9204008FA782 /* DocumentScanner_Example.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 607FACC81AFB9204008FA782 /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 1020; - ORGANIZATIONNAME = CocoaPods; - TargetAttributes = { - 607FACCF1AFB9204008FA782 = { - CreatedOnToolsVersion = 6.3.1; - DevelopmentTeam = NXZW7962A8; - LastSwiftMigration = 1020; - ProvisioningStyle = Automatic; - }; - }; - }; - buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "DocumentScanner" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 607FACC71AFB9204008FA782; - productRefGroup = 607FACD11AFB9204008FA782 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 607FACCF1AFB9204008FA782 /* DocumentScanner_Example */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 607FACCE1AFB9204008FA782 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, - 4480FEFC1FD02641006D99B6 /* PreviewView.xib in Resources */, - 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, - 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - 31C62B1BCE9B481190ABD96C /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-DocumentScanner_Example/Pods-DocumentScanner_Example-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/DocumentScanner/DocumentScanner.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DocumentScanner.framework", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-DocumentScanner_Example/Pods-DocumentScanner_Example-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - C73508E5663D8EC43FDB59FF /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-DocumentScanner_Example-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 607FACCC1AFB9204008FA782 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, - 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, - 4480FEFA1FD0246F006D99B6 /* PreviewView.swift in Sources */, - 441213CC1FE7EA96009B059D /* ScannerViewController.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - 607FACD91AFB9204008FA782 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 607FACDA1AFB9204008FA782 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; - 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = { - isa = PBXVariantGroup; - children = ( - 607FACDF1AFB9204008FA782 /* Base */, - ); - name = LaunchScreen.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 607FACED1AFB9204008FA782 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; - }; - name = Debug; - }; - 607FACEE1AFB9204008FA782 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 607FACF01AFB9204008FA782 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 66FB1A44BD4A9996601D8A98 /* Pods-DocumentScanner_Example.debug.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = NXZW7962A8; - INFOPLIST_FILE = DocumentScanner/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MODULE_NAME = ExampleApp; - PRODUCT_BUNDLE_IDENTIFIER = com.getset.DocScannerExample; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 607FACF11AFB9204008FA782 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 37222C1CD7B9DC95A0852BAC /* Pods-DocumentScanner_Example.release.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = NXZW7962A8; - INFOPLIST_FILE = DocumentScanner/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MODULE_NAME = ExampleApp; - PRODUCT_BUNDLE_IDENTIFIER = com.getset.DocScannerExample; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "DocumentScanner" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 607FACED1AFB9204008FA782 /* Debug */, - 607FACEE1AFB9204008FA782 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "DocumentScanner_Example" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 607FACF01AFB9204008FA782 /* Debug */, - 607FACF11AFB9204008FA782 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 607FACC81AFB9204008FA782 /* Project object */; -} diff --git a/Example/Podfile.lock b/Example/Podfile.lock index e4e627f..d61678f 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -13,4 +13,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 7cfc6a5ca9cae37b2543fa20083bbc420031f30d -COCOAPODS: 1.9.0 +COCOAPODS: 1.15.2 diff --git a/Sources/DocumentScanner/DocScanner.swift b/Sources/DocumentScanner/DocScanner.swift index 6d1c977..a5fa2a6 100644 --- a/Sources/DocumentScanner/DocScanner.swift +++ b/Sources/DocumentScanner/DocScanner.swift @@ -37,6 +37,9 @@ import UIKit /// If true can scan and export multiple documents at onse, defaults to false public var exportMultiple: Bool = false + + ///Maximum number of scans. -1 for unlimited + public var maximumScans = -1 /// Construct scanner object public init(presenter: UIViewController) { @@ -132,8 +135,16 @@ import UIKit // perform perspective correction if let flattened = photo.flattened(rect: self.camera.observationRect) { + self.scannedImages.append(flattened.noiseReducted.rotated) - + + if self.maximumScans != -1 + && self.scannedImages.count >= self.maximumScans { + self.exportMultiple ? self.exportImages?(self.scannedImages) : self.exportImage?(self.scannedImages[0]) + self.scannedImages.removeAll() + self.stopSession() + } + return } @@ -146,6 +157,7 @@ import UIKit // return from manual cropping cropView.onRetake = { self.continueSession() + self.stopSession() } cropView.onRegionSave = { @@ -157,6 +169,13 @@ import UIKit if let flattened = photo.flattened(rect: region) { self.scannedImages.append(flattened.noiseReducted.rotated) + if self.maximumScans != -1 + && self.scannedImages.count >= self.maximumScans { + self.exportMultiple ? self.exportImages?(self.scannedImages) : self.exportImage?(self.scannedImages[0]) + self.scannedImages.removeAll() + self.stopSession() + } + return } @@ -186,6 +205,13 @@ import UIKit let croppedImage = photo.crop(toPreviewLayer: camera.cameraLayer, withRect: regionRect) scannedImages.append(croppedImage.noiseReducted.rotated) + + if self.maximumScans != -1 + && self.scannedImages.count >= self.maximumScans { + self.exportMultiple ? self.exportImages?(self.scannedImages) : self.exportImage?(self.scannedImages[0]) + self.scannedImages.removeAll() + self.stopSession() + } } private func toggleIdle(disabled: Bool) {