Created Protocol to centralize tap detection logic.
This commit is contained in:
parent
767ee787cb
commit
fbc6e83038
@ -26,6 +26,7 @@
|
|||||||
0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */; };
|
0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */; };
|
||||||
0A1B4A96233BB18F005B3FB4 /* CheckboxWithLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */; };
|
0A1B4A96233BB18F005B3FB4 /* CheckboxWithLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */; };
|
||||||
0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */; };
|
0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */; };
|
||||||
|
0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */; };
|
||||||
0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; };
|
0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; };
|
||||||
0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; };
|
0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; };
|
||||||
943784F5236B77BB006A1E82 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F3236B77BB006A1E82 /* GraphView.swift */; };
|
943784F5236B77BB006A1E82 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F3236B77BB006A1E82 /* GraphView.swift */; };
|
||||||
@ -226,6 +227,7 @@
|
|||||||
01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = "<group>"; };
|
01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = "<group>"; };
|
||||||
0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionDetailWithImage.swift; sourceTree = "<group>"; };
|
0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionDetailWithImage.swift; sourceTree = "<group>"; };
|
||||||
0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransaction+Extension.swift"; sourceTree = "<group>"; };
|
0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransaction+Extension.swift"; sourceTree = "<group>"; };
|
||||||
|
0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGuidelinesProtocol.swift; sourceTree = "<group>"; };
|
||||||
0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = "<group>"; };
|
0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = "<group>"; };
|
||||||
0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Checkbox.swift; sourceTree = "<group>"; };
|
0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Checkbox.swift; sourceTree = "<group>"; };
|
||||||
0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxWithLabelView.swift; sourceTree = "<group>"; };
|
0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxWithLabelView.swift; sourceTree = "<group>"; };
|
||||||
@ -438,6 +440,14 @@
|
|||||||
path = FormUIHelpers;
|
path = FormUIHelpers;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
0A5D59C323AD488600EFD9E9 /* Protocols */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */,
|
||||||
|
);
|
||||||
|
path = Protocols;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
D213347423842FE3008E41B3 /* Controllers */ = {
|
D213347423842FE3008E41B3 /* Controllers */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@ -910,6 +920,7 @@
|
|||||||
children = (
|
children = (
|
||||||
D2B18B7E2360913400A9AEDC /* Control.swift */,
|
D2B18B7E2360913400A9AEDC /* Control.swift */,
|
||||||
D2B18B802360945C00A9AEDC /* View.swift */,
|
D2B18B802360945C00A9AEDC /* View.swift */,
|
||||||
|
0A5D59C323AD488600EFD9E9 /* Protocols */,
|
||||||
);
|
);
|
||||||
path = BaseClasses;
|
path = BaseClasses;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -1072,6 +1083,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */,
|
||||||
943784F5236B77BB006A1E82 /* GraphView.swift in Sources */,
|
943784F5236B77BB006A1E82 /* GraphView.swift in Sources */,
|
||||||
D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */,
|
D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */,
|
||||||
DBC4391822442197001AB423 /* CaretView.swift in Sources */,
|
DBC4391822442197001AB423 /* CaretView.swift in Sources */,
|
||||||
|
|||||||
@ -47,18 +47,14 @@ import UIKit
|
|||||||
setupView()
|
setupView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - UITouch
|
// MARK: - AppleGuidelinesProtocol
|
||||||
//--------------------------------------------------
|
extension Control: AppleGuidelinesProtocol {
|
||||||
|
|
||||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||||
|
|
||||||
// If the control is smaller than 44pt by width or height, this will compensate.
|
return Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||||
let faultToleranceX: CGFloat = max((MinimumTappableArea - bounds.size.width) / 2.0, 0)
|
|
||||||
let faultToleranceY: CGFloat = max((MinimumTappableArea - bounds.size.height) / 2.0, 0)
|
|
||||||
let area = bounds.insetBy(dx: -faultToleranceX, dy: -faultToleranceY)
|
|
||||||
return area.contains(point)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// AppleGuidelinesProtocol.swift
|
||||||
|
// MVMCoreUI
|
||||||
|
//
|
||||||
|
// Created by Kevin Christiano on 12/20/19.
|
||||||
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
|
||||||
|
public protocol AppleGuidelinesProtocol {
|
||||||
|
static var minimumTappableArea: CGFloat { get }
|
||||||
|
static func acceptablyOutsideBounds(point: CGPoint, bounds: CGRect) -> Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppleGuidelinesProtocol {
|
||||||
|
|
||||||
|
static public var minimumTappableArea: CGFloat {
|
||||||
|
return 44.0
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the control is smaller than 44pt by width or height, this will compensate.
|
||||||
|
static public func acceptablyOutsideBounds(point: CGPoint, bounds: CGRect) -> Bool {
|
||||||
|
|
||||||
|
let faultToleranceX: CGFloat = max((minimumTappableArea - bounds.size.width) / 2.0, 0)
|
||||||
|
let faultToleranceY: CGFloat = max((minimumTappableArea - bounds.size.height) / 2.0, 0)
|
||||||
|
let area = bounds.insetBy(dx: -faultToleranceX, dy: -faultToleranceY)
|
||||||
|
|
||||||
|
return area.contains(point)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user