updated for buttongroup
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
8fb60fde03
commit
3e8461aef6
@ -71,11 +71,6 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private let lineSpacing: CGFloat = 12.0
|
|
||||||
private let itemSpacing: CGFloat = 16.0
|
|
||||||
private let estimatedCellHeight: CGFloat = 40.0
|
|
||||||
private let estimatedCellWidth: CGFloat = 150.0
|
|
||||||
|
|
||||||
fileprivate lazy var positionLayout = ButtonGroupPositionLayout().with {
|
fileprivate lazy var positionLayout = ButtonGroupPositionLayout().with {
|
||||||
$0.position = .center
|
$0.position = .center
|
||||||
$0.delegate = self
|
$0.delegate = self
|
||||||
@ -173,7 +168,6 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
|
|||||||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ButtonGroupCollectionViewCell else { return UICollectionViewCell() }
|
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ButtonGroupCollectionViewCell else { return UICollectionViewCell() }
|
||||||
cell.subviews.forEach { $0.removeFromSuperview() }
|
cell.subviews.forEach { $0.removeFromSuperview() }
|
||||||
cell.addSubview(button)
|
cell.addSubview(button)
|
||||||
cell.buttonable = button
|
|
||||||
button.pinToSuperView()
|
button.pinToSuperView()
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,32 +9,12 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|
||||||
/// Cell is needed since the buttonable hitArea "can" be outside of it's container rectangle
|
public class ButtonGroupCollectionViewCell: UICollectionViewCell {}
|
||||||
public class ButtonGroupCollectionViewCell: UICollectionViewCell {
|
|
||||||
|
extension ButtonGroupCollectionViewCell: AppleGuidlinesTouchable {
|
||||||
var buttonable: Buttonable?
|
|
||||||
|
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||||
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||||
guard let buttonable else { return nil }
|
|
||||||
|
|
||||||
// Create a minimumHitArea variable with a value that represents the minimum size of the hit area you want to create for the button.
|
|
||||||
let minimumHitArea = CGSize(width: buttonable.intrinsicContentSize.width, height: 44)
|
|
||||||
|
|
||||||
// Create a new hitFrame variable that is the same size as the minimumHitArea variable, but is centered on the button's frame.
|
|
||||||
let hitFrame = CGRect(
|
|
||||||
x: self.bounds.midX - minimumHitArea.width / 2,
|
|
||||||
y: self.bounds.midY - minimumHitArea.height / 2,
|
|
||||||
width: minimumHitArea.width,
|
|
||||||
height: minimumHitArea.height
|
|
||||||
)
|
|
||||||
|
|
||||||
// If the point that was passed to the hitTest(_:with:) method is within the hitFrame, return the button itself. This will cause the button to handle the touch event.
|
|
||||||
if hitFrame.contains(point) {
|
|
||||||
return buttonable
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the point is not within the hitFrame, return nil. This will cause the touch event to be handled by another view.
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -120,7 +120,16 @@ extension UIView {
|
|||||||
|
|
||||||
|
|
||||||
extension UIView {
|
extension UIView {
|
||||||
|
private func removeDebugBorder() {
|
||||||
|
layer.sublayers?.forEach({ layer in
|
||||||
|
if layer.name?.hasPrefix("debug") ?? false {
|
||||||
|
layer.removeFromSuperlayer()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public func debugBorder(show shouldShow: Bool = true, color: UIColor = .red) {
|
public func debugBorder(show shouldShow: Bool = true, color: UIColor = .red) {
|
||||||
|
removeDebugBorder()
|
||||||
if shouldShow {
|
if shouldShow {
|
||||||
let borderLayer = CALayer()
|
let borderLayer = CALayer()
|
||||||
borderLayer.name = "debugAreaLayer"
|
borderLayer.name = "debugAreaLayer"
|
||||||
@ -147,12 +156,6 @@ extension UIView {
|
|||||||
touchLayer.bounds = bounds
|
touchLayer.bounds = bounds
|
||||||
layer.addSublayer(touchLayer)
|
layer.addSublayer(touchLayer)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
layer.sublayers?.forEach({ layer in
|
|
||||||
if layer.name?.hasPrefix("debug") ?? false {
|
|
||||||
layer.removeFromSuperlayer()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user