快速点击多次响应的解决方案

//限制UIView的某些操作在指定时间内只触发一次.
public extension UIView {

private struct FqOnceTapTagKeys {
    static var fqOnceTapTagKey = "fqPushTagKeys"
}

//记录当前是否可以点击跳转.默认为true
@objc dynamic var fqOnceTapTag:Bool {
    set {
        objc_setAssociatedObject(self, &FqOnceTapTagKeys.fqOnceTapTagKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)
    }
    get {
        if let hasPush = objc_getAssociatedObject(self, &FqOnceTapTagKeys.fqOnceTapTagKey) as? Bool {
            return hasPush
        }
        return true
    }
}


/// 限制连续点击多次跳转的异常
/// - Parameters:
///   - intervalTime: 限制触发以后.间隔多长时间可再次触发
///   - handBlock: 触发处理回调
@objc func fqLimitHandingOnce(_ intervalTime : Double = 0.4,handBlock: ()->()) {
    if self.fqOnceTapTag == true {
        self.fqOnceTapTag = false
        handBlock()
        self.perform(#selector(fqCancelLimitHandingOnceTap), afterDelay: intervalTime)
    }
}

//取消限制
@objc func fqCancelLimitHandingOnceTap() {
    self.fqOnceTapTag = true
}
}

你可能感兴趣的:(快速点击多次响应的解决方案)