diff --git a/MiniScanner.xcodeproj/project.pbxproj b/MiniScanner.xcodeproj/project.pbxproj index a5b3754b478b8fb33c26f9ddc1cde619b98229c2..5841e45cff2ec68d9f4b0574ebca2068ae152599 100644 --- a/MiniScanner.xcodeproj/project.pbxproj +++ b/MiniScanner.xcodeproj/project.pbxproj @@ -1111,8 +1111,8 @@ ); mainGroup = EC0CF1F1254D8BBF00888722; packageReferences = ( - 539D1C952C171344009DB24A /* XCRemoteSwiftPackageReference "LNExtensionExecutor.git" */, - 539996522C2711BA00671340 /* XCRemoteSwiftPackageReference "ZLImageEditor.git" */, + 539D1C952C171344009DB24A /* XCRemoteSwiftPackageReference "LNExtensionExecutor" */, + 539996522C2711BA00671340 /* XCRemoteSwiftPackageReference "ZLImageEditor" */, ); productRefGroup = EC0CF1FB254D8BBF00888722 /* Products */; projectDirPath = ""; @@ -1603,7 +1603,7 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 539996522C2711BA00671340 /* XCRemoteSwiftPackageReference "ZLImageEditor.git" */ = { + 539996522C2711BA00671340 /* XCRemoteSwiftPackageReference "ZLImageEditor" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/longitachi/ZLImageEditor.git"; requirement = { @@ -1611,7 +1611,7 @@ minimumVersion = 2.0.2; }; }; - 539D1C952C171344009DB24A /* XCRemoteSwiftPackageReference "LNExtensionExecutor.git" */ = { + 539D1C952C171344009DB24A /* XCRemoteSwiftPackageReference "LNExtensionExecutor" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/LeoNatan/LNExtensionExecutor.git"; requirement = { @@ -1624,12 +1624,12 @@ /* Begin XCSwiftPackageProductDependency section */ 539996532C2711BA00671340 /* ZLImageEditor */ = { isa = XCSwiftPackageProductDependency; - package = 539996522C2711BA00671340 /* XCRemoteSwiftPackageReference "ZLImageEditor.git" */; + package = 539996522C2711BA00671340 /* XCRemoteSwiftPackageReference "ZLImageEditor" */; productName = ZLImageEditor; }; 539D1C962C171344009DB24A /* LNExtensionExecutor */ = { isa = XCSwiftPackageProductDependency; - package = 539D1C952C171344009DB24A /* XCRemoteSwiftPackageReference "LNExtensionExecutor.git" */; + package = 539D1C952C171344009DB24A /* XCRemoteSwiftPackageReference "LNExtensionExecutor" */; productName = LNExtensionExecutor; }; /* End XCSwiftPackageProductDependency section */ diff --git a/MiniScanner.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate b/MiniScanner.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate index 6e83eb66bbd48a0607ebf5e7ab906d31741f9734..ba4ea40d1ef3e9196bf7c5d65ef8f809a33f8580 100644 Binary files a/MiniScanner.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate and b/MiniScanner.xcworkspace/xcuserdata/g.makhoul.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MiniScanner/Modules/EditViewController/CustomViews/BannerView.swift b/MiniScanner/Modules/EditViewController/CustomViews/BannerView.swift index 3cd25b0c3ecb8d648a327438ab483f4e57140e8e..17c78ecf4ab5e0dcd531be4c9d0a2b2d27a7ed8d 100644 --- a/MiniScanner/Modules/EditViewController/CustomViews/BannerView.swift +++ b/MiniScanner/Modules/EditViewController/CustomViews/BannerView.swift @@ -47,7 +47,8 @@ class BannerView: UIView { .coverFlow, .cubic] var options:ImageScannerOptions! - + var deviceOrientationHelper = DeviceOrientationHelper() + fileprivate var typeIndex = 0 { didSet { let type = self.transformerTypes[typeIndex] @@ -106,12 +107,18 @@ class BannerView: UIView { super.layoutSubviews() clearUI() + } // MARK: - Methods private func clearUI() { view.backgroundColor = .clear self.options = ImageScannerOptions() + deviceOrientationHelper.startDeviceOrientationNotifier { (deviceOrientation) in + print("orientation: \(deviceOrientation)") + self.orientationChanged(deviceOrientation: deviceOrientation) + } + } func set(session: MultiPageScanSession) { @@ -135,12 +142,30 @@ class BannerView: UIView { let scannedItem = ScannedItem(originalImage: image ?? UIImage(), quad: nil) scannedItem.colorOption = self.options.defaultColorRenderOption - scannedItem.rotation = 180 + scannedItem.rotation = getCurrentRotationAngle() scannedItem.render { (_) in } self.scanSession?.add(item: scannedItem, at: pagerView.currentIndex) cell?.imageView?.image = image delegate?.update(session: self.scanSession) } + + private func getCurrentRotationAngle()->Double{ + switch self.deviceOrientationHelper.currentDeviceOrientation { + case .landscapeRight: + return -90.0 + case .landscapeLeft: + return 90.0 + case .portrait: + return 0.0 + case .portraitUpsideDown: + return 180.0 + default: + return 0.0 + } + } + private func orientationChanged(deviceOrientation: UIDeviceOrientation) { + print("Orientation changed: \(self.deviceOrientationHelper.currentDeviceOrientation.rawValue)") + } } diff --git a/MiniScanner/Modules/EditViewController/EditViewController.swift b/MiniScanner/Modules/EditViewController/EditViewController.swift index eae8c3c390a623602038bcafe67329031af69267..490d9bf3d6c36c27e9b038a9d1702f01e6e05cb4 100644 --- a/MiniScanner/Modules/EditViewController/EditViewController.swift +++ b/MiniScanner/Modules/EditViewController/EditViewController.swift @@ -38,6 +38,7 @@ public class EditViewController: UIViewController { private var fileURL: URL? var options:ImageScannerOptions! let config = ZLImageEditorConfiguration.default() + var deviceOrientationHelper = DeviceOrientationHelper() var signatureImage = UIImage() var isAll: Bool = false @@ -113,6 +114,13 @@ public class EditViewController: UIViewController { self.present(alertController, animated: true, completion: nil) } } + public override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + deviceOrientationHelper.startDeviceOrientationNotifier { (deviceOrientation) in + print("orientation: \(deviceOrientation)") + self.orientationChanged(deviceOrientation: deviceOrientation) + } + } func configImageEditor() { ZLImageEditorConfiguration.default() @@ -144,7 +152,7 @@ public class EditViewController: UIViewController { if let img = image { let scannedItem = ScannedItem(originalImage: img, renderImage: img, quad: nil) scannedItem.colorOption = self.options.defaultColorRenderOption - scannedItem.rotation = 180 + scannedItem.rotation = getCurrentRotationAngle() self.scanSession = self.scanSession?.replaceAndGet(item: scannedItem, at: banner.pagerView.currentIndex) self.banner.scanSession = self.scanSession self.banner.pagerView.reloadData(at: banner.pagerView.currentIndex ) @@ -157,7 +165,7 @@ public class EditViewController: UIViewController { if let img = image { let scannedItem = ScannedItem(originalImage: img, renderImage: img, quad: nil) scannedItem.colorOption = self.options.defaultColorRenderOption - scannedItem.rotation = 180 + scannedItem.rotation = getCurrentRotationAngle() self.scanSession = self.scanSession?.replaceAndGet(item: scannedItem, at: index) } } @@ -178,7 +186,7 @@ public class EditViewController: UIViewController { if let img = overlayView.cropImage(self.originalImage) { let scannedItem = ScannedItem(originalImage: img, renderImage: img, quad: nil) scannedItem.colorOption = self.options.defaultColorRenderOption - scannedItem.rotation = 180 + scannedItem.rotation = getCurrentRotationAngle() self.scanSession = self.scanSession?.replaceAndGet(item: scannedItem, at: banner.pagerView.currentIndex) self.banner.scanSession = self.scanSession self.banner.pagerView.reloadData(at: banner.pagerView.currentIndex ) @@ -189,6 +197,24 @@ public class EditViewController: UIViewController { } } + private func getCurrentRotationAngle()->Double{ + switch self.deviceOrientationHelper.currentDeviceOrientation { + case .landscapeRight: + return -90.0 + case .landscapeLeft: + return 90.0 + case .portrait: + return 0.0 + case .portraitUpsideDown: + return 180.0 + default: + return 0.0 + } + } + private func orientationChanged(deviceOrientation: UIDeviceOrientation) { + print("Orientation changed: \(self.deviceOrientationHelper.currentDeviceOrientation.rawValue)") + } + @IBAction func backIndex(_ sender: UIButton) { if banner.pagerView.currentIndex != 0 { banner.pagerView.scrollToItem(at: banner.pagerView.currentIndex - 1, animated: true) @@ -337,7 +363,7 @@ public class EditViewController: UIViewController { ZLEditImageViewController.showEditImageVC(parentVC: self, image: img, editModel: nil) { [ ] resImage, editModel in let scannedItem = ScannedItem(originalImage: resImage, renderImage: resImage, quad: nil) scannedItem.colorOption = self.options.defaultColorRenderOption - scannedItem.rotation = 180 + scannedItem.rotation = self.getCurrentRotationAngle() self.scanSession = self.scanSession?.replaceAndGet(item: scannedItem, at: self.banner.pagerView.currentIndex) self.banner.scanSession = self.scanSession self.banner.pagerView.reloadData(at: self.banner.pagerView.currentIndex ) diff --git a/MiniScanner/Supporting Files/CustomWeScan/Scan/DeviceOrientationHelper.swift b/MiniScanner/Supporting Files/CustomWeScan/Scan/DeviceOrientationHelper.swift index bedc5ecabbb76e7cb7c756b32221b17e6b79dbe5..22ed70575f2dbb51da2eec36f4268aef702a98e7 100644 --- a/MiniScanner/Supporting Files/CustomWeScan/Scan/DeviceOrientationHelper.swift +++ b/MiniScanner/Supporting Files/CustomWeScan/Scan/DeviceOrientationHelper.swift @@ -61,7 +61,12 @@ class DeviceOrientationHelper { self.currentDeviceOrientation = newDeviceOrientation if let deviceOrientationHandler = self.deviceOrientationAction { DispatchQueue.main.async { - deviceOrientationHandler!(self.currentDeviceOrientation) + if newDeviceOrientation == .landscapeRight { + deviceOrientationHandler!(.landscapeLeft) + } else { + deviceOrientationHandler!(self.currentDeviceOrientation) + + } } } } diff --git a/MiniScanner/Supporting Files/CustomWeScan/Scan/ScannerViewController.swift b/MiniScanner/Supporting Files/CustomWeScan/Scan/ScannerViewController.swift index e313b973a8f44d58ffcd4bf7312c2daf5ac43bed..026852950522e27a62c2cdf7b24835b14fcc8e8b 100644 --- a/MiniScanner/Supporting Files/CustomWeScan/Scan/ScannerViewController.swift +++ b/MiniScanner/Supporting Files/CustomWeScan/Scan/ScannerViewController.swift @@ -190,6 +190,7 @@ public final class ScannerViewController: UIViewController { updateCounterButton() deviceOrientationHelper.startDeviceOrientationNotifier { (deviceOrientation) in + print("orientation: \(deviceOrientation)") self.orientationChanged(deviceOrientation: deviceOrientation) } } @@ -589,17 +590,6 @@ extension ScannerViewController: CustomTabBarViewDelegate { let bottomSheetController = NBBottomSheetController(configuration: configuration) bottomSheetController.present(popup, on: self) - } else { -// var images: [UIImage] = [] -// for item in multipageSession.scannedItems { -// if let image = item.originalImage?.retrieveImage() { -// images.append(image) -// } -// } -// let previewController = PreviewImageViewController() -// previewController.image = images -// present(previewController, animated: true) - } }