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

58 lines
1.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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