美文网首页
UIButton - 避免多次重复点击

UIButton - 避免多次重复点击

作者: 机智的猪 | 来源:发表于2017-08-30 17:36 被阅读11次
    import Foundation
    import UIKit
    
    extension UIButton {
        
        
        func antiMultiplyTouch(delay: TimeInterval, closure: @escaping () -> Void) {
            self.isUserInteractionEnabled = false
            
            DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
                self.isUserInteractionEnabled = true
                closure()
            }
        }
    }
    
    

    使用时

    
    @objc func buttonClick(button: UIButton) -> Void {
            print("点击了")
            button.antiMultiplyTouch(delay: 2) {
                print("2S后可以再次点击了")
            }
        }
    
    

    更多方案:
    http://www.cocoachina.com/ios/20171108/21086.html

    相关文章

      网友评论

          本文标题:UIButton - 避免多次重复点击

          本文链接:https://www.haomeiwen.com/subject/vljxjxtx.html