Skip to content

Commit a37e14d

Browse files
committed
<FIX> iOS 13 navigation
1 parent 6b5cc2b commit a37e14d

8 files changed

Lines changed: 45 additions & 40 deletions

File tree

Example/MBDocCapture.xcodeproj/project.pbxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
TargetAttributes = {
152152
607FACCF1AFB9204008FA782 = {
153153
CreatedOnToolsVersion = 6.3.1;
154-
DevelopmentTeam = L4QNEF5BYM;
154+
DevelopmentTeam = 3KP92HUCY4;
155155
LastSwiftMigration = 0900;
156156
};
157157
};
@@ -161,6 +161,7 @@
161161
developmentRegion = English;
162162
hasScannedForEncodings = 0;
163163
knownRegions = (
164+
English,
164165
en,
165166
Base,
166167
);
@@ -370,7 +371,7 @@
370371
baseConfigurationReference = 69C18151CF8697B4DFD43821 /* Pods-MBDocCapture_Example.debug.xcconfig */;
371372
buildSettings = {
372373
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
373-
DEVELOPMENT_TEAM = L4QNEF5BYM;
374+
DEVELOPMENT_TEAM = 3KP92HUCY4;
374375
INFOPLIST_FILE = MBDocCapture/Info.plist;
375376
IPHONEOS_DEPLOYMENT_TARGET = 10;
376377
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -387,7 +388,7 @@
387388
baseConfigurationReference = 4A501EB817244E784075C859 /* Pods-MBDocCapture_Example.release.xcconfig */;
388389
buildSettings = {
389390
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
390-
DEVELOPMENT_TEAM = L4QNEF5BYM;
391+
DEVELOPMENT_TEAM = AZ7KRNMEKM;
391392
INFOPLIST_FILE = MBDocCapture/Info.plist;
392393
IPHONEOS_DEPLOYMENT_TARGET = 10;
393394
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/MBDocCapture/Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MBDocCapture.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'MBDocCapture'
3-
spec.version = '0.1.3'
3+
spec.version = '0.1.4'
44
spec.summary = 'MBDocCapture makes it easy to add document scanning functionalities to your iOS.'
55

66
spec.description = <<-DESC

MBDocCapture/Classes/ViewControllers/EditScanViewController.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import UIKit
2828
import AVFoundation
2929

3030
/// The `EditScanViewController` offers an interface for the user to edit the detected rectangle.
31-
final class EditScanViewController: UIViewController {
31+
final class EditScanViewController: UIViewController, UIAdaptivePresentationControllerDelegate {
3232

3333
lazy private var imageView: UIImageView = {
3434
let imageView = UIImageView()
@@ -51,7 +51,7 @@ final class EditScanViewController: UIViewController {
5151
lazy private var nextButton: UIBarButtonItem = {
5252
let title = NSLocalizedString("mbdoccapture.next_button", tableName: nil, bundle: bundle(), value: "Next", comment: "")
5353
let button = UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(pushReviewController))
54-
button.tintColor = navigationController?.navigationBar.tintColor
54+
button.tintColor = .white
5555
return button
5656
}()
5757

@@ -86,6 +86,11 @@ final class EditScanViewController: UIViewController {
8686
title = NSLocalizedString("mbdoccapture.scan_edit_title", tableName: nil, bundle: bundle(), value: "Trimming", comment: "")
8787
navigationItem.rightBarButtonItem = nextButton
8888

89+
if #available(iOS 13.0, *) {
90+
isModalInPresentation = false
91+
navigationController?.presentationController?.delegate = self
92+
}
93+
8994
zoomGestureController = ZoomGestureController(image: image, rectView: rectView)
9095

9196
let touchDown = UILongPressGestureRecognizer(target: zoomGestureController, action: #selector(zoomGestureController.handle(pan:)))
@@ -135,6 +140,10 @@ final class EditScanViewController: UIViewController {
135140
NSLayoutConstraint.activate(rectViewConstraints + imageViewConstraints)
136141
}
137142

143+
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
144+
return false
145+
}
146+
138147
// MARK: - Actions
139148

140149
@objc func pushReviewController() {

MBDocCapture/Classes/ViewControllers/ImageScannerController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ public final class ImageScannerController: UINavigationController {
9494

9595
self.imageScannerDelegate = delegate
9696

97-
navigationBar.tintColor = .black
98-
navigationBar.isTranslucent = false
97+
navigationBar.tintColor = .white
9998
self.view.addSubview(blackFlashView)
10099
setupConstraints()
101100

MBDocCapture/Classes/ViewControllers/ReviewViewController.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import UIKit
2828

2929
/// The `ReviewViewController` offers an interface to review the image after it has been cropped and deskwed according to the passed in rectangle.
30-
final class ReviewViewController: UIViewController {
30+
final class ReviewViewController: UIViewController, UIAdaptivePresentationControllerDelegate {
3131

3232
private var rotationAngle = Measurement<UnitAngle>(value: 0, unit: .degrees)
3333
private var enhancedImageIsAvailable = false
@@ -61,7 +61,7 @@ final class ReviewViewController: UIViewController {
6161
lazy private var doneButton: UIBarButtonItem = {
6262
let title = NSLocalizedString("mbdoccapture.next_button", tableName: nil, bundle: bundle(), value: "Next", comment: "")
6363
let button = UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(finishScan))
64-
button.tintColor = navigationController?.navigationBar.tintColor
64+
button.tintColor = .white
6565
return button
6666
}()
6767

@@ -87,6 +87,11 @@ final class ReviewViewController: UIViewController {
8787
setupToolbar()
8888
setupConstraints()
8989

90+
if #available(iOS 13.0, *) {
91+
isModalInPresentation = false
92+
navigationController?.presentationController?.delegate = self
93+
}
94+
9095
title = NSLocalizedString("mbdoccapture.scan_review_title", tableName: nil, bundle: bundle(), value: "Confirmation", comment: "")
9196
navigationItem.rightBarButtonItem = doneButton
9297
}
@@ -105,6 +110,10 @@ final class ReviewViewController: UIViewController {
105110
navigationController?.setToolbarHidden(true, animated: true)
106111
}
107112

113+
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
114+
return false
115+
}
116+
108117
// MARK: Setups
109118

110119
private func setupViews() {
@@ -149,7 +158,7 @@ final class ReviewViewController: UIViewController {
149158
reloadImage()
150159

151160
if isCurrentlyDisplayingEnhancedImage {
152-
enhanceButton.tintColor = UIColor(red: 64 / 255, green: 159 / 255, blue: 255 / 255, alpha: 1.0)
161+
enhanceButton.tintColor = UIColor(red: 64 / 255.0, green: 159 / 255.0, blue: 255 / 255.0, alpha: 1.0)
153162
} else {
154163
enhanceButton.tintColor = .white
155164
}

MBDocCapture/Classes/ViewControllers/ScannerViewController.swift

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import UIKit
2828
import AVFoundation
2929

3030
/// The `ScannerViewController` offers an interface to give feedback to the user regarding rectangles that are detected. It also gives the user the opportunity to capture an image with a detected rectangle.
31-
final class ScannerViewController: UIViewController {
31+
final class ScannerViewController: UIViewController, UIAdaptivePresentationControllerDelegate {
3232

3333
private var prepOverlayView: UIView!
3434

@@ -40,13 +40,7 @@ final class ScannerViewController: UIViewController {
4040

4141
/// The view that draws the detected rectangles.
4242
private let rectView = RectangleView()
43-
44-
/// The visual effect (blur) view used on the navigation bar
45-
private let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
46-
47-
/// The original bar style that was set by the host app
48-
private var originalBarStyle: UIBarStyle?
49-
43+
5044
lazy private var shutterButton: ShutterButton = {
5145
let button = ShutterButton()
5246
button.translatesAutoresizingMaskIntoConstraints = false
@@ -93,9 +87,7 @@ final class ScannerViewController: UIViewController {
9387

9488
captureSessionManager = CaptureSessionManager(videoPreviewLayer: videoPreviewLayer)
9589
captureSessionManager?.delegate = self
96-
97-
originalBarStyle = navigationController?.navigationBar.barStyle
98-
90+
9991
NotificationCenter.default.addObserver(self, selector: #selector(subjectAreaDidChange), name: NSNotification.Name.AVCaptureDeviceSubjectAreaDidChange, object: nil)
10092
// NotificationCenter.default.addObserver(self, selector: #selector(updateCameraOrientation), name: UIDevice.orientationDidChangeNotification, object: nil)
10193
}
@@ -108,14 +100,7 @@ final class ScannerViewController: UIViewController {
108100
rectView.removeRectangle()
109101
captureSessionManager?.start()
110102
UIApplication.shared.isIdleTimerDisabled = true
111-
112-
navigationController?.navigationBar.isTranslucent = true
113-
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
114-
navigationController?.navigationBar.addSubview(visualEffectView)
115-
navigationController?.navigationBar.sendSubviewToBack(visualEffectView)
116-
117-
navigationController?.navigationBar.barStyle = .blackTranslucent
118-
103+
119104
navigationController?.setToolbarHidden(true, animated: false)
120105

121106
if CaptureSession.current.isScanningTwoFacedDocument {
@@ -134,20 +119,11 @@ final class ScannerViewController: UIViewController {
134119
super.viewDidLayoutSubviews()
135120

136121
videoPreviewLayer.frame = view.layer.bounds
137-
138-
let statusBarHeight = UIApplication.shared.statusBarFrame.size.height
139-
let visualEffectRect = self.navigationController?.navigationBar.bounds.insetBy(dx: 0, dy: -(statusBarHeight)).offsetBy(dx: 0, dy: -statusBarHeight)
140-
141-
visualEffectView.frame = visualEffectRect ?? CGRect.zero
142122
}
143123

144124
override func viewWillDisappear(_ animated: Bool) {
145125
super.viewWillDisappear(animated)
146126
UIApplication.shared.isIdleTimerDisabled = false
147-
148-
visualEffectView.removeFromSuperview()
149-
navigationController?.navigationBar.isTranslucent = false
150-
navigationController?.navigationBar.barStyle = originalBarStyle ?? .default
151127
}
152128

153129
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -183,6 +159,11 @@ final class ScannerViewController: UIViewController {
183159

184160
private func setupNavigationBar() {
185161
navigationItem.setLeftBarButton(cancelButton, animated: false)
162+
163+
if #available(iOS 13.0, *) {
164+
isModalInPresentation = false
165+
navigationController?.presentationController?.delegate = self
166+
}
186167
}
187168

188169
private func setupConstraints() {
@@ -219,6 +200,10 @@ final class ScannerViewController: UIViewController {
219200
NSLayoutConstraint.activate(rectViewConstraints + shutterButtonConstraints + activityIndicatorConstraints)
220201
}
221202

203+
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
204+
return false
205+
}
206+
222207
// MARK: - Tap to Focus
223208

224209
/// Called when the AVCaptureDevice detects that the subject area has changed significantly. When it's called, we reset the focus so the camera is no longer out of focus.

0 commit comments

Comments
 (0)