Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix landscape / portrait mode bug #138

Merged
merged 2 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CardScan/Classes/ScanBaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public protocol TestingImageDataSource: AnyObject {

public var scanEventsDelegate: ScanEvents?

static public var isAppearing = false
static public let machineLearningQueue = DispatchQueue(label: "CardScanMlQueue")
// Only access this variable from the machineLearningQueue
static var hasRegisteredAppNotifications = false
Expand Down Expand Up @@ -231,12 +232,18 @@ public protocol TestingImageDataSource: AnyObject {
return .portrait
}

override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .portrait
}

override open var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

override open func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIDevice.current.setValue(UIDeviceOrientation.portrait.rawValue, forKey: "orientation")
ScanBaseViewController.isAppearing = true
self.ocr.numbers.removeAll()
self.ocr.expiries.removeAll()
self.ocr.firstResult = nil
Expand Down Expand Up @@ -264,6 +271,11 @@ public protocol TestingImageDataSource: AnyObject {
}
}

override open func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
ScanBaseViewController.isAppearing = false
}

public func getScanStats() -> ScanStats {
return self.ocr.scanStats
}
Expand Down
4 changes: 4 additions & 0 deletions Example/CardScan.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
8B35C432628F7822A929E022 /* Pods_CardScan_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D23A15A1FC04B1051F78F83F /* Pods_CardScan_Example.framework */; };
CDE23ECB5AB347EDDBC0BBB6 /* Pods_CardScan_ExampleUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 549CDC3EE835C98A0E3A73B9 /* Pods_CardScan_ExampleUITests.framework */; };
F399939924180A2B00D8ECF5 /* ModalViewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F399939824180A2B00D8ECF5 /* ModalViewViewController.swift */; };
F3BF1C5C22D51AAA002A2575 /* CardScan_BundleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BF1C5B22D51AAA002A2575 /* CardScan_BundleTests.swift */; };
F3FA027023A814C4002A8169 /* CardScan_CardUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FA026F23A814C4002A8169 /* CardScan_CardUtilsTests.swift */; };
F8CAD2C8565738BD646FB707 /* Pods_CardScan_ExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43AD0335DC1ACC5289BDEBF1 /* Pods_CardScan_ExampleTests.framework */; };
Expand Down Expand Up @@ -66,6 +67,7 @@
CAEC04DFEA0EBB109963938F /* Pods-CardScan_ExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CardScan_ExampleTests.release.xcconfig"; path = "Target Support Files/Pods-CardScan_ExampleTests/Pods-CardScan_ExampleTests.release.xcconfig"; sourceTree = "<group>"; };
D23A15A1FC04B1051F78F83F /* Pods_CardScan_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CardScan_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E89BEC885679F7CB00F19F5A /* Pods-CardScan_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CardScan_Example.release.xcconfig"; path = "Target Support Files/Pods-CardScan_Example/Pods-CardScan_Example.release.xcconfig"; sourceTree = "<group>"; };
F399939824180A2B00D8ECF5 /* ModalViewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalViewViewController.swift; sourceTree = "<group>"; };
F3BF1C5B22D51AAA002A2575 /* CardScan_BundleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardScan_BundleTests.swift; sourceTree = "<group>"; };
F3FA026F23A814C4002A8169 /* CardScan_CardUtilsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardScan_CardUtilsTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -151,6 +153,7 @@
607FACDC1AFB9204008FA782 /* Images.xcassets */,
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD31AFB9204008FA782 /* Supporting Files */,
F399939824180A2B00D8ECF5 /* ModalViewViewController.swift */,
);
name = "Example for CardScan";
path = CardScan;
Expand Down Expand Up @@ -485,6 +488,7 @@
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
3B2741C5219F99B700BFA3D2 /* ResultViewController.swift in Sources */,
F399939924180A2B00D8ECF5 /* ModalViewViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 4 additions & 0 deletions Example/CardScan/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return ScanBaseViewController.isAppearing ? UIInterfaceOrientationMask.portrait : UIInterfaceOrientationMask.allButUpsideDown
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
Expand Down
64 changes: 62 additions & 2 deletions Example/CardScan/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -119,6 +119,13 @@
<action selector="scanCardOldDevicePress" destination="vXZ-lx-hvc" eventType="touchUpInside" id="lSb-gT-iHT"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Hq5-Pp-QoB">
<rect key="frame" x="132" y="588" width="111" height="30"/>
<state key="normal" title="Present Modally"/>
<connections>
<segue destination="QHk-Pe-Pgw" kind="show" id="KAt-Cl-VDw"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -133,6 +140,7 @@
<constraint firstItem="lOx-Ed-LOH" firstAttribute="top" secondItem="HGF-3W-kd7" secondAttribute="bottom" constant="8" id="IrW-Pq-bcY"/>
<constraint firstItem="pIK-as-bko" firstAttribute="top" secondItem="6NY-p4-OvD" secondAttribute="bottom" constant="8" id="Jpb-N9-6UO"/>
<constraint firstItem="HGF-3W-kd7" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="LAc-xn-1Rd"/>
<constraint firstItem="Hq5-Pp-QoB" firstAttribute="top" secondItem="lOx-Ed-LOH" secondAttribute="bottom" constant="4.5" id="MBc-bo-mqL"/>
<constraint firstAttribute="trailingMargin" secondItem="ohs-2Q-mlC" secondAttribute="trailing" constant="16" id="MrZ-jD-OY4"/>
<constraint firstItem="LBI-Nj-Ojb" firstAttribute="trailing" secondItem="kh9-bI-dsS" secondAttribute="trailingMargin" id="OZL-nk-k2K"/>
<constraint firstItem="qlz-Ds-Znv" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="Qox-lN-oV9"/>
Expand All @@ -147,6 +155,7 @@
<constraint firstItem="HGF-3W-kd7" firstAttribute="top" secondItem="LBI-Nj-Ojb" secondAttribute="bottom" constant="8" id="n9T-02-cay"/>
<constraint firstItem="6NY-p4-OvD" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="sRZ-M5-dWl"/>
<constraint firstItem="qlz-Ds-Znv" firstAttribute="trailing" secondItem="kh9-bI-dsS" secondAttribute="trailingMargin" id="tRj-Xx-bJf"/>
<constraint firstItem="Hq5-Pp-QoB" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="wMV-F7-j4i"/>
</constraints>
</view>
<connections>
Expand Down Expand Up @@ -249,5 +258,56 @@
</objects>
<point key="canvasLocation" x="885.60000000000002" y="132.68365817091455"/>
</scene>
<!--Modal View View Controller-->
<scene sceneID="KW8-5r-Gdc">
<objects>
<viewController id="s5g-OK-FOJ" customClass="ModalViewViewController" customModule="CardScan_Example" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="gel-rM-WUS"/>
<viewControllerLayoutGuide type="bottom" id="LQA-Lg-cau"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="CIL-DC-8QO">
<rect key="frame" x="0.0" y="0.0" width="375" height="647"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fyx-FO-b7y">
<rect key="frame" x="111.5" y="308.5" width="152" height="30"/>
<state key="normal" title="to ScanViewController"/>
<connections>
<action selector="toScanViewPress:" destination="s5g-OK-FOJ" eventType="touchUpInside" id="zDD-nE-V4P"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="Fyx-FO-b7y" firstAttribute="centerX" secondItem="CIL-DC-8QO" secondAttribute="centerX" id="mjt-nF-ynE"/>
<constraint firstItem="Fyx-FO-b7y" firstAttribute="centerY" secondItem="CIL-DC-8QO" secondAttribute="centerY" id="uiZ-Ty-1rm"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="L9V-TM-YHF"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="97Q-8u-GgH" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="886" y="811"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="mDp-3X-wbx">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="QHk-Pe-Pgw" sceneMemberID="viewController">
<toolbarItems/>
<navigationItem key="navigationItem" id="MZa-kR-PbQ"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="FGP-py-bfx">
<rect key="frame" x="0.0" y="0.0" width="375" height="56"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="s5g-OK-FOJ" kind="relationship" relationship="rootViewController" id="3Fj-RR-Hhq"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Aaw-aD-xr2" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="137" y="811"/>
</scene>
</scenes>
</document>
40 changes: 40 additions & 0 deletions Example/CardScan/ModalViewViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// ModalViewViewController.swift
// CardScan_Example
//
// Created by Jaime Park on 3/10/20.
// Copyright © 2020 CocoaPods. All rights reserved.
//

import Foundation
import UIKit
import CardScan

class ModalViewViewController: UIViewController, ScanDelegate {
func userDidCancel(_ scanViewController: ScanViewController) {
self.navigationController?.popToRootViewController(animated: true)
print("User Did Cancel")
}

func userDidScanCard(_ scanViewController: ScanViewController, creditCard: CreditCard) {
self.navigationController?.popToRootViewController(animated: true)
print("User Did Scan Card \(creditCard.number)")
}

func userDidSkip(_ scanViewController: ScanViewController) {
self.navigationController?.popToRootViewController(animated: true)
print("User Did Skip")
}

override func viewDidLoad() {
super.viewDidLoad()
}

@IBAction func toScanViewPress(_ sender: Any) {
guard let vc = ScanViewController.createViewController(withDelegate: self) else {
return
}
self.navigationController?.pushViewController(vc, animated: true)
}
}

Loading