32 lines
949 B
Swift
32 lines
949 B
Swift
//
|
|
// AppleGuidlinesTouchable.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 4/27/23.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public protocol AppleGuidlinesTouchable {
|
|
static var minimumTappableArea: CGFloat { get }
|
|
static func acceptablyOutsideBounds(point: CGPoint, bounds: CGRect) -> Bool
|
|
}
|
|
|
|
extension AppleGuidlinesTouchable {
|
|
|
|
static public var minimumTappableArea: CGFloat {
|
|
return 45.0
|
|
}
|
|
|
|
// If the control is smaller than 45pt 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)
|
|
|
|
let contains = area.contains(point)
|
|
return contains
|
|
}
|
|
}
|