From f3facb6c5a1e613b309f899626fa2ca277203564 Mon Sep 17 00:00:00 2001 From: Yingtao Guo Date: Thu, 21 Jul 2022 09:22:49 -0400 Subject: [PATCH] fix: restore showRotationDial setting make hiding rotation dial easier and less confusing for users. --- Example/ViewController.swift | 2 +- Sources/Mantis/CropView/CropView.swift | 4 ++-- Sources/Mantis/CropViewConfig.swift | 4 +++- .../RotationDial/RotationDialPlate.swift | 18 +++--------------- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 2129a8fb..7f279ca5 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -76,8 +76,8 @@ class ViewController: UIViewController, CropViewControllerDelegate { } var config = Mantis.Config() - config.cropViewConfig.dialConfig = nil config.showAttachedCropToolbar = false + config.cropViewConfig.showRotationDial = false let cropToolbar = MyNavigationCropToolbar(frame: .zero) let cropViewController = Mantis.cropViewController(image: image, config: config, cropToolbar: cropToolbar) diff --git a/Sources/Mantis/CropView/CropView.swift b/Sources/Mantis/CropView/CropView.swift index b5f42d73..9f823b74 100644 --- a/Sources/Mantis/CropView/CropView.swift +++ b/Sources/Mantis/CropView/CropView.swift @@ -245,7 +245,7 @@ class CropView: UIView { } private func setupAngleDashboard() { - guard let dialConfig = cropViewConfig.dialConfig else { + guard cropViewConfig.showRotationDial else { return } @@ -258,7 +258,7 @@ class CropView: UIView { y: 0, width: boardLength, height: angleDashboardHeight), - dialConfig: dialConfig) + dialConfig: cropViewConfig.dialConfig) self.rotationDial = rotationDial rotationDial.isUserInteractionEnabled = true addSubview(rotationDial) diff --git a/Sources/Mantis/CropViewConfig.swift b/Sources/Mantis/CropViewConfig.swift index 4fa7bd7b..37a88c3d 100644 --- a/Sources/Mantis/CropViewConfig.swift +++ b/Sources/Mantis/CropViewConfig.swift @@ -20,7 +20,9 @@ public struct CropViewConfig { Rotation Dial currently is tightly coupled with other parts of CropView, we see rotation dial as a part of CropView, so we put dialConfig inside CropViewConfig */ - public var dialConfig: DialConfig? = DialConfig() + public var dialConfig = DialConfig() + + public var showRotationDial = true var minimumBoxSize: CGFloat = 42 diff --git a/Sources/Mantis/RotationDial/RotationDialPlate.swift b/Sources/Mantis/RotationDial/RotationDialPlate.swift index 4543b411..e6fc6452 100644 --- a/Sources/Mantis/RotationDial/RotationDialPlate.swift +++ b/Sources/Mantis/RotationDial/RotationDialPlate.swift @@ -69,10 +69,7 @@ class RotationDialPlate: UIView { let mark = CAShapeLayer() mark.frame = CGRect(x: 0, y: 0, width: 2, height: 2) mark.path = UIBezierPath(ovalIn: mark.bounds).cgPath - - if let dialConfig = dialConfig { - mark.fillColor = dialConfig.smallScaleColor.cgColor - } + mark.fillColor = dialConfig.smallScaleColor.cgColor return mark } @@ -82,18 +79,12 @@ class RotationDialPlate: UIView { mark.frame = CGRect(x: 0, y: 0, width: 4, height: 4) mark.path = UIBezierPath(ovalIn: mark.bounds).cgPath - if let dialConfig = dialConfig { - mark.fillColor = dialConfig.smallScaleColor.cgColor - } + mark.fillColor = dialConfig.smallScaleColor.cgColor return mark } private func setupAngleNumber() { - guard let dialConfig = dialConfig else { - return - } - let numberFont = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.caption2) let cgFont = CTFontCreateUIFontForLanguage(.label, numberFont.pointSize/2, nil) @@ -164,11 +155,8 @@ class RotationDialPlate: UIView { width: radius, height: radius) layer.path = UIBezierPath(ovalIn: layer.bounds).cgPath + layer.fillColor = dialConfig.centerAxisColor.cgColor - if let dialConfig = dialConfig { - layer.fillColor = dialConfig.centerAxisColor.cgColor - } - self.layer.addSublayer(layer) }