Visual_Novel_iOS/crush/Crush/Src/Components/UI/Buttons/CLButton.swift

58 lines
1.4 KiB
Swift
Raw Normal View History

2025-10-09 10:29:35 +00:00
//
// CLButton.swift
// Crush
//
// Created by Leon on 2025/9/25.
//
import UIKit
class CLButton: UIButton {
/// 0.8s
var clickInterval: TimeInterval = 0.8
private var isIgnoringEvent = false
override func sendAction(_ action: Selector, to target: Any?, for event: UIEvent?) {
if isIgnoringEvent {
//
return
}
if clickInterval > 0 {
isIgnoringEvent = true
DispatchQueue.main.asyncAfter(deadline: .now() + clickInterval) { [weak self] in
self?.isIgnoringEvent = false
}
}
super.sendAction(action, to: target, for: event)
}
}
class CLControl: UIControl {
/// 0.8s
@IBInspectable var clickInterval: TimeInterval = 0.8
private var isIgnoringEvent = false
override func sendAction(_ action: Selector, to target: Any?, for event: UIEvent?) {
if isIgnoringEvent {
//
return
}
if clickInterval > 0 {
isIgnoringEvent = true
DispatchQueue.main.asyncAfter(deadline: .now() + clickInterval) { [weak self] in
self?.isIgnoringEvent = false
}
}
super.sendAction(action, to: target, for: event)
}
}