Fixed bug with repeating keys in PN keyboard

This commit is contained in:
Selim Mustafaev 2023-01-09 23:58:49 +03:00
parent 3f2df89fd0
commit 5be64456c3
4 changed files with 20 additions and 17 deletions

View File

@ -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;

View File

@ -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)
}
}

View File

@ -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() {

View File

@ -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) {