From 5be64456c3121f8b2c12de9a3105cd275e2e2931 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Mon, 9 Jan 2023 23:58:49 +0300 Subject: [PATCH] Fixed bug with repeating keys in PN keyboard --- AutoCat.xcodeproj/project.pbxproj | 4 ++-- AutoCat/ACUIKit/Extensions/UIEdgeInsets.swift | 12 ++++++++++++ AutoCat/Controllers/NewNumberController.swift | 2 +- AutoCat/Views/PNKeyboard.swift | 19 +++++-------------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 4d2fa39..8ea48ab 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -1136,7 +1136,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 101; + CURRENT_PROJECT_VERSION = 102; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -1161,7 +1161,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 101; + CURRENT_PROJECT_VERSION = 102; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat/ACUIKit/Extensions/UIEdgeInsets.swift b/AutoCat/ACUIKit/Extensions/UIEdgeInsets.swift index aa8a553..14c1be3 100644 --- a/AutoCat/ACUIKit/Extensions/UIEdgeInsets.swift +++ b/AutoCat/ACUIKit/Extensions/UIEdgeInsets.swift @@ -5,6 +5,10 @@ extension UIEdgeInsets { init(all: CGFloat) { self.init(top: all, left: all, bottom: all, right: all) } + + init(vertical: CGFloat, horizontal: CGFloat) { + self.init(top: vertical, left: horizontal, bottom: vertical, right: horizontal) + } } extension UIEdgeInsets { @@ -12,4 +16,12 @@ extension UIEdgeInsets { static func all(_ value: CGFloat) -> UIEdgeInsets { .init(all: value) } + + static func vertical(_ value: CGFloat) -> UIEdgeInsets { + .init(vertical: value, horizontal: 0) + } + + static func horizontal(_ value: CGFloat) -> UIEdgeInsets { + .init(vertical: 0, horizontal: value) + } } diff --git a/AutoCat/Controllers/NewNumberController.swift b/AutoCat/Controllers/NewNumberController.swift index 5155582..5965cc3 100644 --- a/AutoCat/Controllers/NewNumberController.swift +++ b/AutoCat/Controllers/NewNumberController.swift @@ -58,7 +58,7 @@ class NewNumberController: UIViewController { super.viewDidLoad() view.addSubview(mainStackView) - mainStackView.pin(to: view, insets: .init(top: 16, left: 16, bottom: 16, right: 16)) + mainStackView.pin(to: view, insets: .all(16)) } func check() { diff --git a/AutoCat/Views/PNKeyboard.swift b/AutoCat/Views/PNKeyboard.swift index 0804a01..f98f830 100644 --- a/AutoCat/Views/PNKeyboard.swift +++ b/AutoCat/Views/PNKeyboard.swift @@ -1,11 +1,11 @@ import UIKit import AutoCatCore -protocol PNKeyboardDelegate: class { +protocol PNKeyboardDelegate: AnyObject { func returnClicked() } -protocol PNButtonDelegate: class { +protocol PNButtonDelegate: AnyObject { func buttonTapped(_ button: PNButton) } @@ -17,8 +17,6 @@ enum PNButtonType { class PNButton: UIButton { private(set) var type: PNButtonType - private var timer: Timer? - private var waitCount = 0 private var rectLayer = CAShapeLayer() private var bgColor = UIColor(named: "KeyBackground") @@ -63,13 +61,15 @@ class PNButton: UIButton { self.layer.addSublayer(self.rectLayer) self.imageView?.layer.zPosition = 2 + self.contentEdgeInsets = .vertical(12) + self.rectLayer.shadowColor = UIColor.black.cgColor self.rectLayer.shadowOpacity = 0.4 self.rectLayer.shadowOffset = CGSize(width: 0.0, height : 1.0) self.rectLayer.shadowRadius = radius self.addTarget(self, action: #selector(buttonDown), for: .touchDown) - self.addTarget(self, action: #selector(buttonUp), for: [.touchUpInside, .touchUpOutside]) + self.addTarget(self, action: #selector(buttonUp), for: [.touchUpInside, .touchUpOutside, .touchCancel]) self.addTarget(self, action: #selector(touchUpInside), for: .touchUpInside) } @@ -81,19 +81,10 @@ class PNButton: UIButton { @objc func buttonDown(_ sender: PNButton) { sender.layer.opacity = 0.3 - self.timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: { _ in - self.waitCount += 1 - if self.waitCount > 5 { - self.delegate?.buttonTapped(self) - } - }) } @objc func buttonUp(_ sender: PNButton) { sender.layer.opacity = 1 - self.timer?.invalidate() - self.timer = nil - self.waitCount = 0 } @objc func touchUpInside(_ sender: PNButton) {