private struct AssociatedKeys { static var acceptEventInterval = "acceptEventInterval" static var waitingTime = "waitingTime" }
acceptEventInterval用来记录点击间隔
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/// 按钮点击间隔时间 public var acceptEventInterval: TimeInterval { get { if let acceptEventInterval = objc_getAssociatedObject(self, &AssociatedKeys.acceptEventInterval) as? TimeInterval { return acceptEventInterval } return 0.0 } set { assert(newValue > 0, "acceptEventInterval should be valid") methodSwizzling() objc_setAssociatedObject(self, &AssociatedKeys.acceptEventInterval, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) } }
waitingTime 用来记录上次有效点击的时间戳
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/// 当前等待时间 private var waitingTime: TimeInterval { get { if let waitingTime = objc_getAssociatedObject(self, &AssociatedKeys.waitingTime) as? TimeInterval { return waitingTime } return 0.0 } set { objc_setAssociatedObject(self,&AssociatedKeys.waitingTime,newValue,.OBJC_ASSOCIATION_RETAIN_NONATOMIC) } }